在CodeIgniter的钩子中使用Loader类 [英] Use Loader class within a hook in CodeIgniter
问题描述
我有一个钩子函数:
public function checkIfLogged(){
$ this- CI =& get_instance();
if(!$ this-> CI-> session-> userdata('logged')){
$ this-> CI-> load-&家');
exit;
}
}
我的问题是 $ this-> CI-> load-> view('common / home');
实际上不加载模板文件。是否有任何问题为什么?
我使用了post_controller_constructor钩子。
谢谢,
Peter
pre_system
早在系统执行期间。此时只有基准和钩子类被加载。没有发生路由或其他进程。
pre_controller
您的任何控制器被调用。所有基类,路由和安全检查已完成。
post_controller_constructor
post_controller
在您的控制器完全执行后立即调用。
display_override
覆盖_display()函数,用于在系统执行结束时将完成的页面发送到Web浏览器。这允许您使用自己的显示方法。请注意,您将需要使用$ this-> CI =& get_instance(),然后通过调用$ this-> CI-> output-> get_output()
cache_override / p>
允许您调用自己的函数,而不是输出类中的_display_cache()函数。这允许您使用自己的缓存显示机制。
post_system
在最终呈现的页面被发送到浏览器之后,在系统执行结束后,最终的数据被发送到浏览器。
所以
我认为你正在寻找的是 display_override
,但你也可以看看这里 CodeIgniter是否必须在最后一步加载视图?
I have this function that is in a hook:
public function checkIfLogged() {
$this->CI = & get_instance();
if(!$this->CI->session->userdata('logged') ){
$this->CI->load->view('common/home');
exit;
}
}
My problem is that the $this->CI->load->view('common/home');
doesn't actually load the template file at all. Is there any resons why?
I am using a post_controller_constructor hook.
Thanks, Peter
pre_system
Called very early during system execution. Only the benchmark and hooks class have been loaded at this point. No routing or other processes have happened.
pre_controller
Called immediately prior to any of your controllers being called. All base classes, routing, and security checks have been done.
post_controller_constructor
Called immediately after your controller is instantiated, but prior to any method calls happening.
post_controller
Called immediately after your controller is fully executed.
display_override
Overrides the _display() function, used to send the finalized page to the web browser at the end of system execution. This permits you to use your own display methodology. Note that you will need to reference the CI superobject with $this->CI =& get_instance() and then the finalized data will be available by calling $this->CI->output->get_output()
cache_override
Enables you to call your own function instead of the _display_cache() function in the output class. This permits you to use your own cache display mechanism.
post_system
Called after the final rendered page is sent to the browser, at the end of system execution after the finalized data is sent to the browser.
so
i think the one you are looking for is display_override
but you can also take a look here Does CodeIgniter have to load view in the final step?
这篇关于在CodeIgniter的钩子中使用Loader类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!