当我登录时,我正在尝试为codeigniter项目设置一些用户活动,以便查看哪些用户登录和注销。
在我的库函数登录上,我在下面有这些数据但现在抛出错误不确定如何修复它。
$activity_data = array(
'user_id' => $this->CI->session->userdata('user_id'),
'name' => $this->CI->session->userdata('firstname') . ' ' . $this->CI->session->userdata('lastname')
);
$this->CI->load->model('admin/common/user_login_model');
// Error Here Line 27
$this->user_login_model->addActivity('login', $activity_data);
错误
A PHP Error was encountered
Severity: Notice
Message: Undefined property: User::$user_login_model
Filename: libraries/User.php
Line Number: 27
Fatal error: Call to a member function addActivity() on a non-object in C:\Xampp\htdocs\codeigniter-cms\application\libraries\User.php on line 27
在模型上
public function addActivity($key, $data) {
$data['user_id'] = $this->user->getID();
if (isset($data['user_id'])) {
$user_id = $data['user_id'];
} else {
$user_id = 0;
}
$this->db->query("INSERT INTO `" . $this->db->dbprefix . "user_activity` SET
`user_id` = '" . (int)$user_id . "',
`key` = " . $this->db->escape($key) . ",
`data` = " . $this->db->escape(serialize($data)) . ",
`ip` = " . $this->db->escape($this->input->server('REMOTE_ADDR')) . ",
`date_added` = NOW()
");
}
答案 0 :(得分:0)
您似乎创建了CI的实例并将模型加载到其中。但是,您尝试使用$this->user_login_model
直接从库类访问模型,这是错误的。请尝试改为:
$this->CI->user_login_model->addActivity('login', $activity_data);