Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter-如何扩展两个核心类_Php_Codeigniter - Fatal编程技术网

Php Codeigniter-如何扩展两个核心类

Php Codeigniter-如何扩展两个核心类,php,codeigniter,Php,Codeigniter,我也是Codeigniter和PHP的高手 我想问一下,我可以从 系统/核心/某些文件 进入 应用程序/core/MY\u一些文件 我试图为某个包含不允许字符的url创建自定义异常错误,因此如果存在不允许字符,则应该重定向到我的自定义控制器 这是我的自定义核心文件(my_URI): 这是系统工作流中的一个早期点,因此您还无法访问某些对象。 但您可以使用自定义错误页面: 在application/errors文件夹中创建一个名为error_400.PHP的PHP文件 例如,使用此内容 <!

我也是Codeigniter和PHP的高手
我想问一下,我可以从

系统/核心/某些文件


进入

应用程序/core/MY\u一些文件


我试图为某个包含不允许字符的url创建自定义异常错误,因此如果存在不允许字符,则应该重定向到我的自定义控制器

这是我的自定义核心文件(my_URI):


这是系统工作流中的一个早期点,因此您还无法访问某些对象。
但您可以使用自定义错误页面:
在application/errors文件夹中创建一个名为error_400.PHP的PHP文件 例如,使用此内容

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Error</title>
</head>
<body>
<div id="container">
    <h1><?php echo $heading; ?></h1>
    <?php echo $message; ?>
</div>
</body>
</html>

错误
(但也许您可以复制错误_general.php并根据需要进行修改)。
然后,在重写的URI类中,您可以像这样显示自定义页面(而不是重定向):


现在错误无法访问MY_URI文件,它总是从system/coreNow中的URI.php加载消息不是因为MY_URI没有加载,而是错误消息没有显示为我在MY_URI中编辑的内容,应该编辑的错误页面在文件夹视图/error/html中
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Error</title>
</head>
<body>
<div id="container">
    <h1><?php echo $heading; ?></h1>
    <?php echo $message; ?>
</div>
</body>
</html>
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_URI extends CI_URI {
    /**
     * Filter segments for malicious characters
     *
     * @access  private
     * @param   string
     * @return  string
     */
    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))
            {
                $_error =& load_class('Exceptions', 'core');
                echo $_error->show_error('The URI you submitted has disallowed characters.', 'The URI you submitted has disallowed characters.', 'error_400', 400);
                exit;
            }
        }

        // Convert programatic characters to entities
        $bad    = array('$',        '(',        ')',        '%28',      '%29');
        $good   = array('&#36;',    '&#40;',    '&#41;',    '&#40;',    '&#41;');

        return str_replace($bad, $good, $str);
    }
}