codeigniter 安全扩展不起作用,覆盖 csrf_show_error 消息

codeigniter security extend not working, overwrite csrf_show_error message

CI版本:2.2.0

我在 /CI220/application/libraries/MY_Security.php 创建了一个文件 我设置的配置文件

$config['subclass_prefix'] = 'MY_';

我发现它没有加载 MY_Security,我的 MY_Controller 正在加载,但不是这个库。下面是我的调用堆栈日志:

Call Stack
#   Time    Memory  Function    Location
1   0.0004  242064  {main}( )   ../index.php:0
2   0.0009  244352  require_once( '/Users/User/Sites/CI220/system/core/CodeIgniter.php' )   ../index.php:202
3   0.0091  478200  load_class( )   ../CodeIgniter.php:213
4   0.0096  489872  CI_Input->__construct( )    ../Common.php:174
5   0.0097  491432  CI_Input->_sanitize_globals( )  ../Input.php:103
6   0.0232  499224  CI_Security->csrf_verify( ) ../Input.php:647
7   0.0233  499432  CI_Security->csrf_show_error( ) ../Security.php:149

我没有从安全性加载我的扩展库。我想覆盖 csrf_show_error 函数

public function csrf_show_error()
{
    show_error('The action you have requested is not allowed.!!!');
}

感谢@Svetlio 的回答

libraries/MY_Security.php 是错误的路径,它必须在核心文件夹中 > core/MY_Security.php

我因为这个页面而感到困惑。 http://www.codeigniter.com/user_guide/general/creating_libraries.html

Extending Native Libraries

If all you need to do is add some functionality to an existing library - perhaps add a function or two - then it's overkill to replace the entire library with your version. In this case it's better to simply extend the class. Extending a class is nearly identical to replacing a class with a couple exceptions:

The class declaration must extend the parent class. Your new class name and filename must be prefixed with MY_ (this item is configurable. See below.). For example, to extend the native Email class you'll create a file named application/libraries/MY_Email.php, and declare your class with:.....

感谢您的回答,所以如果您发现 libraries 文件夹不起作用可以尝试 core 文件夹。

Security class 位于 system/core/Security.php

Email class 位于 system/libraries/Email.php

核心class可以参考这篇link: http://www.codeigniter.com/user_guide/general/core_classes.html

核心 classes 总是自动加载的,因此您不需要也包含在自动加载中。