我已经为查询日志创建了一个钩子。
第1步:config.php中的$config['enable_hooks'] = TRUE;
第2步:
$hook['post_controller'] = array(
'class' => 'Db_log',
'function' => 'logQueries',
'filename' => 'db_log.php',
'filepath' => 'hooks'
);
// hooks.php
步骤3:Hooks文件夹创建了名为Db_log.php的文件
步骤4:$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 . " \n Execution Time:" . $times[$key];
fwrite($handle, $sql . "\n\n");
}
$line .= "-----------------------------------------------\n";
fwrite($handle, $line . "\n");
fclose($handle); // Close the file
}
}
我的问题是当控制器被调用时,钩子在本地正常运行 在服务器挂钩不工作,设置权限755,777,644,但仍然无法正常工作。
答案 0 :(得分:0)
请在hooks.php中更改数组,如下所示
$hook['post_controller'] = array(
'class' => 'Db_log',
'function' => 'logQueries',
'filename' => 'Db_log.php',
'filepath' => 'hooks'
);
您写错了文件名