CodeIgniter Forums
Error: Call to undefined method CI_Input::CI_Input - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Error: Call to undefined method CI_Input::CI_Input (/thread-43524.html)



Error: Call to undefined method CI_Input::CI_Input - El Forum - 07-14-2011

[eluser]Unknown[/eluser]
Hi all wonderful CI people! Smile

I have just upgraded from 1.7.. to 2.0.2 and are moving my old code to the new structure.
I have MY_input witch is modifying header information and I have moved to the core dir.
Can anyone help me figuring out why I get an error?
See below for details.

The error:
Fatal error: Call to undefined method CI_Input::CI_Input() in /xxxx/www/application/core/MY_Input.php on line 7

The code for MY_input:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Input extends CI_Input {

    var $_headers = false;

    function MY_Input() {
        parent::CI_Input();
        $this->_headers = $this->_clean_input_data($this->_get_headers());
    }

    function header($index = '', $xss_clean = false) {
        return $this->_fetch_from_array(
            $this->_headers,
            $index,
            $xss_clean
        );
    }

    function _get_headers() {
        if (function_exists('getallheaders')) {
            $headers = $this->_clean_input_data(getallheaders());
        } else {
            $headers = array();

            foreach ($_SERVER as $key => $val) {
                if (preg_match('/^http/i', $key)) {
                    $key = $this->_clean_input_keys(
                        str_replace(
                            ' ',
                            '-',
                            ucwords(
                                str_replace(
                                    array('http_', '_'),
                                    array('', ' '),
                                    strtolower($key)
                                )
                            )
                        )
                    );
                    $val = $this->_clean_input_data($val);
                    $headers[$key] = $val;
                }
            }
        }

        return $headers;
    }

}



Error: Call to undefined method CI_Input::CI_Input - El Forum - 07-14-2011

[eluser]Eric Barnes[/eluser]
Remember ci 2 is php5 only -
Code:
function MY_Input() {
        parent::CI_Input();
        $this->_headers = $this->_clean_input_data($this->_get_headers());
    }

should be:
Code:
public function __construct() {
        parent::__construct();
        $this->_headers = $this->_clean_input_data($this->_get_headers());
    }



Error: Call to undefined method CI_Input::CI_Input - El Forum - 07-14-2011

[eluser]Unknown[/eluser]
Thanks, it got me abit further. Smile

But I'm not quite there, I have php 5.3 installed. But the code is not mine, but I'm trying to convert it, and I'm abit rocky to what this is doing. I think it' supposed to change the header, but it doesn't do anything. Except the welcome script, that is working now.

Any ideas?