如何更改codeigniter中显示的错误 [英] How to change an error displayed in codeigniter
问题描述
您提交的URI不允许使用字符。
如何截获此错误?是他们的 callback _
函数?当我尝试在URL中使用=时发生此错误。例如。我放1 = 1 - 我得到这个错误。而不是错误页面,我想要 redirect('main / cate / page');
捕获此错误并重定向,而不是显示遇到错误页面
看起来错误被抛在 system / core / URI.php
。幸运的是,您可以扩展核心类。在 application / core
中创建一个名为 MY_URI.php
的文件,并覆盖函数:
class MY_URI extends CI_URI {
function __construct(){
parent :: __ construct();
}
function _filter_uri($ str){
if($ str!=''&& $ this-> config-> item('permitted_uri_chars')!='在PHP 5.3转义中,'&&& $ this-> config-> item('enable_query_strings')== FALSE)
{
// preg_quote除了 - preg_quote()是维持向后
//兼容性,因为许多人不知道如何在allowed_uri_chars中的字符将被解析为正则表达式模式
if(!preg_match(| ^ [。 str_replace(array('\\-','\-'),' - ',preg_quote($ this-> config-> item('permitted_uri_chars'),' - '))]] + $ | i,$ str))
{
redirect('main / cate / page');
}
}
//将编程字符转换为实体
$ bad = array('$','(',')','%28' ,'%29');
$ good = array('$','(',')','(',')')
return str_replace($ bad,$ good,$ str);
}
}
The URI you submitted has disallowed characters.
How do I intercept this error? Is their a callback_
function? This error occurs when I try to use an = in the URL. E.g. I put 1=1 -- I get this this error. Instead of the error page I want to redirect('main/cate/page');
How do I catch this error and redirect instead of displaying "An error was encountered page"
Looks like the error is being thrown in system/core/URI.php
. Luckily, you can extend core classes. Create a file in application/core
called MY_URI.php
and override the function:
class MY_URI extends CI_URI{
function __construct(){
parent::__construct();
}
function _filter_uri($str){
if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
{
// preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
// compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str))
{
redirect('main/cate/page');
}
}
// Convert programatic characters to entities
$bad = array('$', '(', ')', '%28', '%29');
$good = array('$', '(', ')', '(', ')');
return str_replace($bad, $good, $str);
}
}
这篇关于如何更改codeigniter中显示的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!