如何从ci3中的hooks文件加载模型



我正在学习如何在ci3中使用钩子,是否可以从ci3中的钩子文件加载模型?因为当我试图加载模型时,它会给我一个错误:

A PHP Error was encountered
Severity: Warning
Message: Undefined property: Http_request_logger::$load
Filename: hooks/http_request_logger.php
Line Number: 9

An uncaught Exception was encountered
Type: Error
Message: Call to a member function model() on null
Filename: D:xampphtdocsvobot-cmsapplicationhookshttp_request_logger.php
Line Number: 9

这是我的钩子代码:

<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Http_request_logger {
public function activity_user() {
$CI = & get_instance();
$this->load->model('./activity_user/MActivityUser');

// log_message('info', 'GET --> ' . var_export($CI->input->get(null), true));
$post = log_message('info', 'POST --> ' . var_export($CI->input->post(null), true));                
// log_message('info', '$_SERVER -->' . var_export($_SERVER, true));
$this->MActivityUser->insertLogActivity( $data = array(  
'username' => (!$this->MActivityUser->getUsername() ? NULL : $this->MActivityUser->getUsername()),
// 'domain' => $_SERVER["SERVER_NAME"],
'menu_name' => $_SERVER["REQUEST_URI"],
'activity' => $post,
// 'ip' => $this->CI->input->ip_address(),
'create_date' => date('Y-m-d H:i:s'),
'cms_id' => $this->MActivityUser->getUserId()
));
return $data;
}
}

错误是您正在将CI实例加载到$CI变量中,但没有使用它来加载模型。

$CI = & get_instance();
$this->load->model('./activity_user/MActivityUser');

应该是

$CI = & get_instance();
$CI->load->model('./activity_user/MActivityUser');

相关内容

  • 没有找到相关文章

最新更新