【问题标题】:Fatal error: Call to undefined method CI_Controller::CI_Controller() IN Codeigniter致命错误:调用未定义的方法 CI_Controller::CI_Controller() IN Codeigniter
【发布时间】:2014-03-07 12:18:02
【问题描述】:

您好,这是我的代码,我在第 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

【问题讨论】:

  • 试试parent::__construct()

标签: php methods codeigniter-2


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-20
    • 2013-11-04
    • 1970-01-01
    • 2013-02-18
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多