1

I have Placed the codeigniter code controller and it throws a error Call to undefined method CI_Controller::CI_Controller().Pls help me to rectify the issue. Controller:

<?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');
        }       
    }   

}
1
  • 1
    replace parent::CI_Controller (); with parent::__construct(); Commented Nov 20, 2013 at 10:26

4 Answers 4

1

That's not how you call the parent constructor. See this

parent::__construct();
Sign up to request clarification or add additional context in comments.

Comments

0

If you are using a latest version of CodeIgniter replace this line of code with this:

From parent::CI_Controller (); to parent::__construct();

Comments

0

In order to run a parent constructor, one would have to explicitly call parent::__construct()

function __construct()
{
   parent::__construct();
   $this->is_logged_in();
}

Ex: Ref: http://php.net/manual/en/language.oop5.decon.php

 class SubClass extends BaseClass {
   function __construct() {
   parent::__construct();
   print "In SubClass constructor\n";
  }
 }

Comments

0

If you're using CI 2.x then your class constructor should look like this:

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

read more in user guide

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.