本文介绍了CodeIgniter:Hooks(pre_controller)加载助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的pre_controller钩子中加载cookie助手,用于我们网站上的记住我功能。我认为创建CI对象的实例$ ci =& get_instance();

I am trying to load the cookie helper in my pre_controller hook for a 'remember me' function on our site. I thought that creating an instance of the CI object with $ci =& get_instance(); would allow me to access to loading helpers but this is not the case.

想法?

 $ci =& get_instance();
 $ci->load->helper('cookie');
 // does not load


推荐答案

code> pre_controller 钩子在超级对象完全构造之前执行,因此 get_instance()无法工作 - 静态对象

The pre_controller hook executes before the super object has been fully constructed, so get_instance() can't work - the static object it returns a reference to hasn't yet been initialized.

请考虑使用 post_controller_constructor 钩子;您的控制器的构造函数将已执行,并且CI超级对象将可供使用。

Consider using the post_controller_constructor hook instead; your controller's constructor will have executed, and the CI super object will be available for use.

这篇关于CodeIgniter:Hooks(pre_controller)加载助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 09:58