Hooks 在 CodeIgniter 2.X 中不起作用
我已经在 config.php 中启用了钩子,
$config['enable_hooks'] = TRUE;
这里是 hook.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| Hooks
| -------------------------------------------------------------------------
| This file lets you define "hooks" to extend CI without hacking the core
| files. Please see the user guide for info:
|
| http://codeigniter.com/user_guide/general/hooks.html
|
*/
$hook['post_controller_constructor'] = array(
'class' => 'Authorization',
'function' => 'authorize',
'filename' => 'authorization.php',
'file_path' => 'hooks'
);
/* End of file hooks.php */
/* Location: ./application/config/hooks.php */
,这里是 application/hooks/ 下的authorization.php 文件,
<?php
class Authorization {
private $ci;
function __construct()
{
parent::__construct();
$this->ci = get_instance();
}
function authorize()
{
echo 'This should be outputed';
}
}
?>
但它不起作用。没有人知道为什么吗?
I've enable hooks in config.php
$config['enable_hooks'] = TRUE;
here is the hook.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| Hooks
| -------------------------------------------------------------------------
| This file lets you define "hooks" to extend CI without hacking the core
| files. Please see the user guide for info:
|
| http://codeigniter.com/user_guide/general/hooks.html
|
*/
$hook['post_controller_constructor'] = array(
'class' => 'Authorization',
'function' => 'authorize',
'filename' => 'authorization.php',
'file_path' => 'hooks'
);
/* End of file hooks.php */
/* Location: ./application/config/hooks.php */
and here is the authorization.php file under application/hooks/
<?php
class Authorization {
private $ci;
function __construct()
{
parent::__construct();
$this->ci = get_instance();
}
function authorize()
{
echo 'This should be outputed';
}
}
?>
but it doesn't work. doesn't anybody know why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在使用 Codigniter 2.1 并且它可以工作..但是我的钩子文件被称为“MainLoader”并且像这样开始:
我希望它有帮助:-)
I am using Codigniter 2.1 and it works.. but my hook file is called 'MainLoader' and starts like this:
I hope it helps :-)
我认为您错过了数组变量旁边的 [] 。
在您的代码中写道:
我认为应该是这样的:
注意 $hook['post_controller_constructor'] 变量旁边的 [] 。
希望这有帮助。谢谢..
I think you missed the [] next to the array variable.
In your code it written :
I think it should be like this :
note the [] next to the $hook['post_controller_constructor'] variable.
Hope this help. Thank you..