Error in php file

柔情痞子 提交于 2019-12-11 11:44:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!