致命错误:在第 8 行调用 C:xampphtdocsCodeIgniterapplicationc


Fatal error: Call to undefined method CI_Controller::CI_Controller() in C:xampphtdocsCodeIgniterapplicationcontrollershello.php on line 8

致命错误:调用未定义的方法 CI_Controller::CI_Controller() in C:''xampp''htdocs''CodeIgniter''application''controllers''hello.php on 第 8 行

我是框架的新手。我在做一个小应用程序时在CodeIgniter中遇到了上述错误。请帮助我..我的代码如下

<?php 
class Hello extends CI_Controller {
var $name;
var $color;
function Hello()
{
parent::CI_Controller();
$this->name= 'Andi';
$this->color= 'red';
}
function you()
{
$data['name'] = $this->name;
$data['color'] = $this->color;
$this->load->views('you_view', $data);
}
}
?>

替换此函数:

function Hello()
{
    parent::CI_Controller();
    $this->name     =   'Andi';
    $this->color    =   'red';
}

跟:

public function __construct() {
    parent::__construct();
    $this->name     =   'Andi';
    $this->color    =   'red';
}

注意:在最新版本的Codeigniter中,您需要
使用构造函数而不是类名作为构造函数。

您使用了 php 5,在 php

5 中,编写构造函数的方式是 __construct(),而 php 4 允许开发人员将构造函数编写为您在代码中使用的类名。

所以,请将您的构造函数写为...

function __construct()
{
    parent::CI_Controller();
    $this->name= 'Andi';
    $this->color= 'red';
}

我想你的问题会解决的。

相关文章:
  • 没有找到相关文章