CodeIgniter Forums
Unable to locate the model you have specified error - 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: Unable to locate the model you have specified error (/thread-43801.html)

Pages: 1 2


Unable to locate the model you have specified error - El Forum - 07-23-2011

[eluser]Shannon[/eluser]
I am trying to make a login page from a tutorial. Whenever I submit the form, it says it can't locate the model I am trying to access.

membership_model.php
Code:
<?php

class Membership_model extends CI_Model {
    
    function validate() {
        $this->db->where('username', $this->input->post('username'));
        $this->db->where('password', md5($this->input->post('password')));
        $query = $this->db->get('lightpanel_login');
        
        if ($query->num_rows == 1) {
            return true;
        }
    }
}
?>

login.php
Code:
<?php

class Login extends CI_Controller {
    
    function __construct() {
        parent::__construct();
    }
    
    function index() {
        $data['main_content'] = 'login_form';
        $this->load->view('includes/template', $data);
    }
    
    function validate_credentials() {
        $this->load->model('membership_model');
        $query = $this->membership_model->validate();
        
        if($query)
        {
            $data = array(
                'username' => $this->input->post('username'),
                'is_logged_in' => true
            );
            
            $this->session->set_userdata($data);
            redirect('index/members_area');
        }
        
        else
        {
            $this->index();
        }
    }
}

?>

I can't really know how to explain it, so if you can ask me questions to try manipulate the problem I will be more than happy to answer them.

Also, today is my first day using CI.

Thanks,
Shannon.


Unable to locate the model you have specified error - El Forum - 07-23-2011

[eluser]jzmwebdevelopement[/eluser]
Shannon,

Have you loaded your model at all?


Unable to locate the model you have specified error - El Forum - 07-23-2011

[eluser]Shannon[/eluser]
What do you mean have I loaded my model at all? Not sure what you mean. Can you explain it a little more please.

EDIT: Yes, I have loaded it in the first line of the validate_credentials function.


Unable to locate the model you have specified error - El Forum - 07-24-2011

[eluser]jzmwebdevelopement[/eluser]
[quote author="Shannon" date="1311504566"]What do you mean have I loaded my model at all? Not sure what you mean. Can you explain it a little more please.

EDIT: Yes, I have loaded it in the first line of the validate_credentials function.[/quote]

Shannon,

CI has a very specific user guide have a read here: http://ellislab.com/codeigniter/user-guide/general/models.html

Jess


Unable to locate the model you have specified error - El Forum - 07-24-2011

[eluser]Wondering Coder[/eluser]
why don't you try loading your model in the __contruct() so even if refresh or accessing other function in same controller it will be readily available.


Unable to locate the model you have specified error - El Forum - 07-24-2011

[eluser]jzmwebdevelopement[/eluser]
[quote author="Shannon" date="1311504566"]What do you mean have I loaded my model at all? Not sure what you mean. Can you explain it a little more please.

EDIT: Yes, I have loaded it in the first line of the validate_credentials function.[/quote]

You have
Code:
$this->load->model('membership_model');
try
Code:
$this->load->model('Membership_model');



Unable to locate the model you have specified error - El Forum - 07-24-2011

[eluser]Shannon[/eluser]
I already tried that, makes no difference.


Unable to locate the model you have specified error - El Forum - 07-24-2011

[eluser]Aziz Chouhan[/eluser]
hi shannon

all i read about your post i found some mistaken concepts.
like
1. you make your model looking correct,but it can work perfectly when it calls from a controller.
2. make a controller which is called when a page is submitted to the server
3. in that controller
a. first load your model
$this->load->model('Membership_model');
b. then call your model function
$this->Membership_model-> validate()

that you have done in your code

4. all before your code ,you are missing this in you model code

function __construct()
{
// Call the Model constructor
parent::__construct();
}

this is very important,and always use this,ok

now i think your code will run successfully.

for full help of code reply me


enjoy


Unable to locate the model you have specified error - El Forum - 07-24-2011

[eluser]Aken[/eluser]
Yeah, your loading code is fine, but you need the __construct() function to call parent::__construct(), as Aziz said.


Unable to locate the model you have specified error - El Forum - 07-24-2011

[eluser]Shannon[/eluser]
I'm getting a ton of errors now, I can't even get back to my login page.