根据此处的 Codeigniter 文档:http://ellislab.com/codeigniter/user-guide/general/hooks.html http://ellislab.com/codeigniter/user-guide/general/hooks.html它指出:
预控制器
在调用任何控制器之前立即调用。所有基类、路由和安全检查都已完成。
但是,如果我创建一个钩子 pre_controller 钩子:
$hook['pre_controller'][] = array(
'class' => 'tester',
'function' => 'test',
'filename' => 'tester.php',
'filepath' => 'models',
//'params' => array('beer', 'wine', 'snacks')
);
文件 tester.php 是:
class tester extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->load->library('migration');
}
public function test()
{
echo "hi";
exit;
}
}
我收到此错误:
Fatal error: Class 'CI_Model' not found in ******.php
为什么没有加载CI_Model?如果我放一个 require_once('system/core/Model.php');在 pre_controller 定义上方的 hooks.php 文件中,我收到以下错误:
Fatal error: Call to a member function library() on a non-object in ****.php
因为它实际上并没有加载CI_Model,函数如图书馆()行不通。我怎样才能强制它引导CI_Model.
第一个说“Use post_controller_constructor
“将被拍摄,因为这不能回答问题。我需要它在运行控制器类中的任何构造函数之前加载它。我需要访问权限来扩展CI_Model类来自预控制器 hook.