Search code examples
phpcodeignitercodeigniter-2codeigniter-urlcodeigniter-routing

Override get_config (Codeigniter)


I am upgrading my Codeigniter from 2.2.1 to 3.0.0. A lot of things has been changed espacially sessions.

CI 2.2.1 and before had this function as follow in system/core/Common.php: Line around 214.

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

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

This is the function that extends 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;
    }

    }

Until here everything worked fine. After upgrading to CI# system/core/Common.php has changed the function to: Line around 238

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

      if (empty($config))
      {

How could I match the param for this function in MY_Input.php

  $config = &get_config('config');

Solution

  • The word 'Array' before $replace in the v3 code enforces the type of the argument, that is the reason you are getting the error.

    'config' was not a valid value for that argument. Remove it and you should be good to go.

        $config = &get_config('config');
    

    to

       $config = &get_config('');