致命错误:调用未定义的方法CI_Controller :: CI_Controller()IN Codeigniter

时间:2014-03-07 12:18:03

标签: php methods codeigniter-2

嗨,这是我的代码,我在第14行有一个错误,为什么? 我在配置文件中定义了base_url和css。

    <?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);
        }
    }

错误:

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

1 个答案:

答案 0 :(得分:4)

如果要调用CI_Controller的构造函数,请使用__construct();

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