问题描述
我刚刚开始查看钩子今天不是100%肯定我做错了,但我得到一个错误,当我尝试和使用$ ci对象在我的函数。
I've just started looking at hooks today not 100% sure what I'm doing wrong but I'm getting an error when I try and use the $ci object in my function.
遇到PHP错误
严重性:注意
消息:尝试获取非对象的属性
文件名:hooks / language .php
行号:12
A PHP Error was encounteredSeverity: NoticeMessage: Trying to get property of non-objectFilename: hooks/language.phpLine Number: 12
我的hooks文件看起来像这样。它在我的应用程序文件夹的hooks目录中。
My hooks file looks like this. It's in the hooks directory in my application folder.
class Language{
var $ci;
public function __construct(){
$this->ci =& get_instance();
}
function get_language(){
echo $this->ci->session->userdata('language');
}
}
我需要获取会话中的值才能使用在我的功能。我不应该这样做吗?
I need to get the value in the session to use in my function. Am I not supposed to do it like this?
感谢您!
推荐答案
在Base4 / 5.php文件中,get_instance()函数被写入,它被有条件地加载,所以它不会存在,直到它被加载。这就是它给错误的原因。
In the Base4/5.php file the get_instance() function is written and it is conditionally loaded so it won’t be present until after it is loaded. And that's the reason its giving error.
这篇关于codeigniter钩子不能得到$ ci对象工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!