根据此处的Codeignitor文档:http : //ellislab.com/codeigniter/user-guide/general/hooks.html,它指出:
pre_controller在调用任何控制器之前立即调用。所有基类,路由和安全性检查均已完成。
但是,如果我使用以下方法创建一个钩子pre_controller钩子:
$hook['pre_controller'][] = array(
'class' => 'tester',
'function' => 'test',
'filename' => 'tester.php',
'filepath' => 'models',
//'params' => array('beer', 'wine', 'snacks')
);
Run Code Online (Sandbox Code Playgroud)
文件tester.php是:
class tester extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->load->library('migration');
}
public function test()
{
echo "hi";
exit;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Fatal error: Class 'CI_Model' not found in ******.php
Run Code Online (Sandbox Code Playgroud)
为什么不加载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 …Run Code Online (Sandbox Code Playgroud)