CodeIgniter Forums
Call to undefined method CI_Controller::CI_Controller() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Call to undefined method CI_Controller::CI_Controller() (/thread-59494.html)



Call to undefined method CI_Controller::CI_Controller() - El Forum - 10-11-2013

[eluser]huangxiao[/eluser]
Hi i just want to ask why is it that i have this error
Quote:Call to undefined method CI_Controller::CI_Controller()
can yo help me please why


Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Success extends CI_Controller{

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

   }


    function members_area(){

        $this->load->view('members_area');
    }


    function is_logged_in(){
        $this->session->userdata('is_logged_in');

       if(is_logged_in != true){
          echo "Not allowed here";
       }
    }

}

Thank you in advance.


Call to undefined method CI_Controller::CI_Controller() - El Forum - 10-11-2013

[eluser]CroNiX[/eluser]
in your constructor, parent should be __construct();

Code:
parent::__construct();
http://ellislab.com/codeigniter/user-guide/general/controllers.html#constructors


Call to undefined method CI_Controller::CI_Controller() - El Forum - 10-11-2013

[eluser]huangxiao[/eluser]
Hi already change it as your suggested but i have problem in the redirect(), it will duplicate the url when i submit the form.
something like this.
[qoute]http://localhost/test/index.php/login/localhost/test/index.php/success/members_area[/qoute]


Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller{

     function index(){

       $data['maincontent'] = "login_view";
       $this->load->view("include/template",$data);

    }


    function getlogin(){
      $this->load->model('login_model');
   $query =  $this->login_model->login_check();

      if($query){
         $data = array(
             'username'=>$this->input->post('username'),
             'is_logged_in'=>true


         );

          $this->session->set_userdata($data);

          redirect('/success/members_area');

      }


   }

}



This is my form

Code:
<div class='container'>
    
      &lt;form class="login" action="index.php/login/getlogin" method='post'&gt;
        <h2>Log-in</h2>
        
           &lt;input type='text' placeholder="username" name="username"&gt;
           &lt;input type='text' placeholder="password"  name="password"&gt;
           <button type="submit" >Log-in</button>

       &lt;/form&gt;
    </div>



Call to undefined method CI_Controller::CI_Controller() - El Forum - 10-12-2013

[eluser]huangxiao[/eluser]
[quote author="CroNiX" date="1381520213"]in your constructor, parent should be __construct();

Code:
parent::__construct();
http://ellislab.com/codeigniter/user-guide/general/controllers.html#constructors[/quote]

Hi what is wrong for my redirect()?