gpt4 book ai didi

php - 调用未定义的方法 CI_Controller::Controller()

转载 作者:可可西里 更新时间:2023-11-01 13:03:38 26 4
gpt4 key购买 nike

我有这个 Controller :

    class Start extends CI_Controller{
var $base;
var $css;

function Start()
{
parent::Controller(); //error here.
$this->base = $this->config->item('base_url'); //error here
$this->css = $this->config->item('css');

}

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

它在这一行中告诉我:

父级:: Controller ();//此处出错。

 Call to undefined method CI_Controller::Controller() 

如果我删除该行..我会在下一行收到一条错误消息..

Call to a member function item() on a non-object

如何防止此类错误的发生?

最佳答案

如果您使用的是 CI 2.x,那么您的类构造函数应该如下所示:

   public function __construct()
{
parent::__construct();
// Your own constructor code
}

阅读更多 user guide

关于php - 调用未定义的方法 CI_Controller::Controller(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9314502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com