我已经放置了代码点火器代码控制器,它抛出了一个错误调用未定义的方法CI_controller::CI_Coontroller()。请帮助我纠正这个问题。控制器:
<?php
class Site1 extends CI_Controller
{
function __construct()
{
parent::CI_Controller ();
$this->is_logged_in();
}
function members_area()
{
$this->load->view('index');
}
function another_page() // just for sample
{
echo 'good. you''re logged in.';
}
function is_logged_in()
{
$is_logged_in = $this->session->userdata('is_logged_in');
if(!isset($is_logged_in) || $is_logged_in != true)
{
echo 'You don''t have permission to access this page. <a href="../login">Login</a>';
die();
//$this->load->view('login_form');
}
}
}
这不是调用父构造函数的方式。查看此
parent::__construct();
如果您使用的是CodeIgniter的最新版本,请将这行代码替换为:
从parent::CI_Controller ();
到parent::__construct();
为了运行父构造函数,必须显式调用parent::__construct()
function __construct()
{
parent::__construct();
$this->is_logged_in();
}
Ex:参考:http://php.net/manual/en/language.oop5.decon.php
class SubClass extends BaseClass {
function __construct() {
parent::__construct();
print "In SubClass constructor'n";
}
}
如果您使用的是CI2.x,那么您的类构造函数应该如下所示:
public function __construct()
{
parent::__construct();
// Your own constructor code
}
阅读更多用户指南