user2991258
user2991258

Reputation: 129

Fatal Error :: Call to undefined method in codeigniter

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

}

Upvotes: 1

Views: 9484

Answers (4)

Suvash sarker
Suvash sarker

Reputation: 3170

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

Upvotes: 0

Krish R
Krish R

Reputation: 22741

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";
  }
 }

Upvotes: 0

Justin Paul Pa&#241;o
Justin Paul Pa&#241;o

Reputation: 936

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

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

Upvotes: 0

Achrome
Achrome

Reputation: 7821

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

parent::__construct();

Upvotes: 1

Related Questions