0

I am new to codeigniter and I am having some issues loading a model in my constructor method. Could someone help me out? Below is the code from the controller I am trying to load the model from...

 <?php

    class Login extends CI_Controller {

        function Login(){
            $this->load->model('membership_model');
        }

        public function index(){
            $this->load->view('login_view.php');
        }

        public function authenticate(){
            $user = $this->input->post('username');
            $pass = sha1($this->input->post('password'));
            if($user != null && $pass != null){
                $access = $this->membership_model->request_access($user, $pass);
                if($access == true){
                    $cookie = array(
                        'name'   => 'username',
                        'value'  => $user,
                        'expire' => '86500',
                        'domain' => 'unleashourmedia.com',
                        'path'   => '/',
                        'prefix' => '',
                        'secure' => TRUE
                    );

                    $this->input->set_cookie($cookie);
                    echo "cookie";
                } else {
                    redirect('login');
                }
            }
        }

    }

?>
2
  • What's the issue? Any error messages? Commented Nov 4, 2011 at 6:00
  • can u display what is the error message you are getting??? Commented Nov 4, 2011 at 7:08

3 Answers 3

1

The problem is you are not calling the constructor of the parent class.

Add this as the first line in your constructor:

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

Comments

0
   function Login(){
  $this->load->model("membership_model","",TRUE); 
  }

2 Comments

This just makes the model auto-connect to the database, I don't see the point of doing this here (though I must say the question isn't clear at all on what the problem is )
Here is the error message: Fatal error: Call to a member function model() on a non-object in /homepages/21/d255080677/htdocs/du/ci/application/controllers/login.php on line 6
0
    //make sure you call parent constructor before anything in that constructor like this
    function Login(){
        parent::__construct();
        $this->load->model('membership_model');
    }

    //and you may also try to name the constructor __construct
    function __construct(){
        parent::__construct();
        $this->load->model('membership_model');
    }

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.