我们如何在CodeIgniter中在全球范围内发挥功能



我对大家都有查询,我想在Codeigniter中在全球范围内函数:

 $ci =& get_instance();

我有致命错误:

Fatal error: Uncaught Error: Using $this when not in object context:

我想使用$ ci for $ this,但是我怎么能提到$ ci =&get_instance()全球?

我必须放置$ ci =&get_instance();每个功能和每个文件中的代码。请帮助。

这是我的测试代码:

    public static function index()
    {   
    $ci =& get_instance();
    $redirect   = $ci->auth->is_logged_in(false, false);
    }

已解决:

问题是PHP版本:

旧版本

$this->employees_model->get_all();

新版本

$ci =& get_instance();
$ci->employees_model->get_all();

您可以创建助手...因为您可以使用$ ci =&get_instance();&直接在控制器,模型,查看等中访问

example :
if (!function_exists('isLogin'))
{
    function isLogin(){
        //get main CodeIgniter object
        $ci =& get_instance();
        //your code
    }
} 
access directly isLogin() in controller like:
if(isLogin())
{
//Your code
}

最新更新