问题
I'm receiving the following error:
Fatal error: Class 'parents' not found in C:\xampp\htdocs\rpo\application\controllers\Home.php on line 7
Here is my code:
class Home extends CI_Controller
{
function __construct()
{
parents::__construct();
}
function index()
{
if($this->session->userdata('logged_in'))
{
$session_data=$this->session->userdata('logged_in');
$data['username']=$session_data['username'];
$this->load->view('home_view',$data);
}
else
{
redirect('login','refresh');
}
}
function logout()
{
$this->session->unset_userdata('logged_in');
session_destroy();
redirect('home','refresh');
}
line 7 is parents::__construct();
回答1:
"parents" should be "parent" in your constructor. parent is a keyword in PHP.
parent::__construct();
回答2:
In your constructor This should be
function __construct()
{
parent::__construct(); // Calling parent class constructors
}
not
parents::__construct();
来源:https://stackoverflow.com/questions/21349816/error-in-php-file