覆盖 get_config (Codeigniter)

Override get_config (Codeigniter)

我正在将我的 Codeigniter 从 2.2.1 升级到 3.0.0。很多东西已经改变,特别是会话。

CI 2.2.1 及之前的版本在 system/core/Common.php: Line around 214.

中有如下功能
   function &get_config($replace = array())
     {
        static $_config;

        if (isset($_config))
    {
        return $_config[0];
    }

这是扩展system/core/Input的函数。php

application/core/MY_Input.php

    Class MY_Input extends CI_Input
    {

     function _clean_input_keys($str, $fatal = true)
     {

    $config = &get_config('config');

    if ( ! preg_match("/^[".$config['permitted_uri_chars']."]+$/i", 
       rawurlencode($str)))
    {
        exit('Disallowed Key Characters.');
    }

    // Clean UTF-8 if supported
    if (UTF8_ENABLED === TRUE)
    {
        $str = $this->uni->clean_string($str);
    }


    return $str;
    }

    }

到这里为止一切正常。升级到CI#后system/core/Common.php功能更改为:Line around 238

    function &get_config(Array $replace = array())
      {
      static $config;

      if (empty($config))
      {

如何在 MY_Input.php

中匹配此函数的参数
  $config = &get_config('config');

像这样尝试

$config=array('db'=>'some value','someother'=>'value');
 $config = &get_config($config);  **//  LINE 6** 

v3 代码中 $replace 之前的单词 'Array' 强制执行参数类型,这就是您收到错误的原因。

'config' 不是该参数的有效值。删除它,你应该很高兴。

    $config = &get_config('config');

   $config = &get_config('');