Search code examples
phpmethodscodeigniter-2

Fatal error: Call to undefined method CI_Controller::CI_Controller() IN Codeigniter


Hi this my code and i have an error in line 14, why? i defined base_url and css in config file.

    <?php
        class Start extends CI_Controller{
            var $base;
            var $css;

            public function Start(){
            parent::CI_Controller();
            $this->base = $this->config->item('base_url');
            $this->css = $this->config->item('css');
        }

        public function hello($name){
           $data['css'] = $this->css;
           $data['base'] = $this->base;
           $data['mytitle'] = 'Welcome to site';
           $data['mytext'] = "Hello, $name, now we're getting dynamic";
           $this->load->view('testview', $data);
        }
    }

ERROR :

     Fatal error: Call to undefined method CI_Controller::CI_Controller() in C:\wamp\www\sandbox\application\controllers\start.php on line 14

Solution

  • If you want to call constructor of CI_Controller then use __construct();

        public function Start(){
        parent::__construct();
        $this->base = $this->config->item('base_url');
        $this->css = $this->config->item('css');