扩展的URI如何加载?
本帖最后由 pung4pung 于 2010-11-20 15:38 编辑由于需要中文URI,根据论坛上的指导。扩展URI类:
/**
* 使URI支持中文
* 如果URL里有空格,urlencode会将空格转换成+,则改$config['permitted_uri_chars'] = ‘a-z 0-9~%.:_\+\-’;
* @author Administrator
*
*/
class MY_URI extends CI_URI {
function _filter_uri($str)
{
if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
{
$str = urlencode($str);
// 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))
{
show_error('The URI you submitted has disallowed characters.', 400);
}
}
$str = urldecode($str);
// Convert programatic characters to entities
$bad = array('$', '(', ')', '%28', '%29');
$good = array('$', '(', ')', '(', ')');
return str_replace($bad, $good, $str);
}
}
把文件存为:application/libraries/MY_URI.php。测试还是The URI you submitted has disallowed characters.
更改核心的URI.php,可以成功使用中文URL,所以应该是这个扩展类没有运行。
请问:哪里漏了改吗? 手册上只说将文件名改为MY_XXX,放在application/libraries/下会自动使用的呀。
HELP!!
已解决!!
原来:1.7.2版本是 To use one of your own system classes instead of a default one simply place your version inside your local application/libraries directory。
我用的是2.0版本,是 For example, to extend the native Input class you'll create a file named application/core/MY_Input.php, and declare your class with。
把MY_URI.php移到 application/core目录下,就OK了! 默认确实是 MY_ 的。
URI 类也会自动加载。
但是,MY_ 这个前缀是可配置的,在 config/config.php 中。
楼主仔细检查一下,肯定是可以自动加载的。 奇怪。
$config['subclass_prefix'] = 'MY_';
没错呀。
还是不行。
页:
[1]