doujianchao7446 2015-10-06 05:08
浏览 54

在codeigniter中,挂钩无法在服务器上运行

I have created a hook for query log. Step 1 : $config['enable_hooks'] = TRUE; in config.php

Step 2 :

 $hook['post_controller'] = array(
    'class' => 'Db_log',
    'function' => 'logQueries', 
    'filename' => 'db_log.php', 
    'filepath' => 'hooks' 
);
// hooks.php

Step 3 : Hooks folder created the file called Db_log.php

Step 4 : Code in // Name of Class as mentioned in $hook['post_controller]

class Db_log {

    function __construct() {
        // Anything except exit()
    }

    // Name of function same as mentioned in Hooks Config
    function logQueries() {
        $CI = &get_instance();
        $filepath = APPPATH . 'logs/Query-log-' . date('Y-m-d') . '.php';
        $handle = fopen($filepath, "a+");
        $times = $CI->db->query_times;
        foreach ($CI->db->queries as $key => $query) {
            date_default_timezone_set("Asia/Bangkok");
            $sql = $query . " 
 Execution Time:" . $times[$key];
            fwrite($handle, $sql . "

");
        }
        $line .= "-----------------------------------------------
";
        fwrite($handle, $line . "
");
        fclose($handle);      // Close the file
    }
}

My Question is When ever controller is call then hook is running properly in local On server hook is not working, Set the permission 755,777,644 but still not working.

  • 写回答

1条回答 默认 最新

  • duandi4815 2015-10-06 05:48
    关注

    Please change array in hooks.php as bellow

    $hook['post_controller'] = array(
        'class' => 'Db_log',
        'function' => 'logQueries', 
        'filename' => 'Db_log.php', 
        'filepath' => 'hooks' 
    );
    

    You have written wrong file name

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器