Welcome Guest, Not a member yet? Register   Sign In
Call to undefined method
#1

[eluser]darshanchalla[/eluser]
Hi,
i am getting this error like call to undefined method plz help me to solve this issue


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



Thanks&Regards;
#2

[eluser]PhilTem[/eluser]
Call

Code:
parent::__construct()

Since CI 2.x there is no more Controller but a CI_Controller class. That's why it does not work for you.

Secondly, please use [ code ] tags (without the spaces) if you want to post code.
#3

[eluser]darshanchalla[/eluser]
so what do i need to do with my code i am using this code for the session
#4

[eluser]darshanchalla[/eluser]
[quote author="PhilTem" date="1359809746"]Call

Code:
parent::__construct()

Since CI 2.x there is no more Controller but a CI_Controller class. That's why it does not work for you.

Secondly, please use [ code ] tags (without the spaces) if you want to post code.[/quote]



[quote i have done like this way still i am getting same error plz help me to solve it.
#5

[eluser]CroNiX[/eluser]
Post the whole controller, not just the constructor. Is your class extending CI_Controller or just Controller? I'm guessing you're extending Controller since that's how you originally had the construct.

http://ellislab.com/codeigniter/user-gui...llers.html
#6

[eluser]darshanchalla[/eluser]
i am sending u the two controller that i am using
Code:
(1)  controller::=site.php
<?php
class site extends ci_controller{
   function __construct()
    {  
      parent::__construct();
     $this->is_logged_in();
    }

function members_area()
{
  $this->load->view('members_area');}
}
function is_logged_in()
{
    $is_logged_in=$this->session->userdata('is_logged_in');
    if(!isset($is_logged_in)||$is_logged_in!=true)
    {
       echo 'You Dont have permission to access this page.<a href="../login">Login</a>';
    die();
    }
}
?&gt;


(2)controller::=login.php

&lt;?php
class Login extends Ci_controller{
function index()
     {
   $data['main_content']='login_form';
   $this->load->view('include/template',$data);
  }
       function validate_credentials(){
          $this->load->model('member_model');
          $query=$this->member_model->validate();
          if($query)
              {
             $data=array(
             'username'=>$this->input->post('username'),
             'is_logged_in'=>true);
             $this->session->set_userdata($data);
             redirect('site/members_area');
           }
      else
          {
          $this->index();
       }
                                   }
  function signup()
  {
   $data['main_content']='signup_form';
   $this->load->view('include/template',$data);
  }
  function create_member()
  {
   $this->load->library('form_validation');
   $this->form_validation->set_rules('first_name','First Name','trimrequired');
   $this->form_validation->set_rules('last_name','Last Name','trimrequired');
   $this->form_validation->set_rules('username','Username','trimrequired|min_length[4]');
   $this->form_validation->set_rules('password','Password','trimrequired|min_length[4]|max_length[32]');
   $this->form_validation->set_rules('password2','Password Confirmation','trimrequired|matches[password]');
   if($this->form_validation->run() ==FALSE)
   {
    $this->signup();
   }
   else
   {
     $this->load->model('member_model');
     if($query=$this->member_model->create_member()){
      $data['main_content']='signup_successful';
      $this->load->view('include/template',$data);
   }
   else
   {
     $this->load->view('signup_form');
   }
  
  }

}}
?&gt;
#7

[eluser]PhilTem[/eluser]
First things first: Keep consistency with CI naming conventions, i.e., it's always

CI_Controller

meaning C, I, and C (of Controller) are capitalized.

Secondly, controller classes also need to be capitalized, i.e., in your case Site.

These things should, in the short run, solve your problem.
#8

[eluser]darshanchalla[/eluser]
HI ,
i am new to codeigniter here i am sending you the code whereas i am getting the error please give me solution as soon as possible and i am using codeigniter 2.1.3



(1) Site Controller site.php
Code:
&lt;?php
class Site extends CI_Controller{
  function __construct()
    {  
      parent::__construct();
      $this->is_logged_in();
  
    }

function members_area()
{
  $this->load->view('members_area');}
}
function is_logged_in()
{
    $is_logged_in=$this->session->userdata('is_logged_in');
    if(!isset($is_logged_in)||$is_logged_in!=true)
    {
       echo 'You Dont have permission to access this page.<a href="../login">Login</a>';
    die();
    }
    
}
?&gt;
(2) Login controller

&lt;?php
class Login extends CI_Controller{
function index()
     {
   $data['main_content']='login_form';
   $this->load->view('include/template',$data);
  }
       function validate_credentials(){
          $this->load->model('member_model');
          $query=$this->member_model->validate();
          if($query)
              {
             $data=array(
             'username'=>$this->input->post('username'),
             'is_logged_in'=>true);
             $this->session->set_userdata($data);
             redirect('site/members_area');
           }
      else
          {
          $this->index();
       }
                                   }
  function signup()
  {
   $data['main_content']='signup_form';
   $this->load->view('include/template',$data);
  }
  function create_member()
  {
   $this->load->library('form_validation');
   $this->form_validation->set_rules('first_name','First Name','trimrequired');
   $this->form_validation->set_rules('last_name','Last Name','trimrequired');
   $this->form_validation->set_rules('username','Username','trimrequired|min_length[4]');
   $this->form_validation->set_rules('password','Password','trimrequired|min_length[4]|max_length[32]');
   $this->form_validation->set_rules('password2','Password Confirmation','trimrequired|matches[password]');
   if($this->form_validation->run() ==FALSE)
   {
    $this->signup();
   }
   else
   {
     $this->load->model('member_model');
     if($query=$this->member_model->create_member()){
      $data['main_content']='signup_successful';
      $this->load->view('include/template',$data);
             }
           else
             {
                 $this->load->view('signup_form');
             }
  
     }

}
}
?&gt;
#9

[eluser]Aken[/eluser]
It says exactly what line the error is on. You're calling a method that doesn't exist. If you don't understand that, you should take some time to learn more about PHP and object orientated programming.




Theme © iAndrew 2016 - Forum software by © MyBB