Following is the scenario:
I’ve integrated HMVC in CodeIgniter 2.0.2. Created a module with following structure.
/application/modules/login
/application/modules/login/controllers
/application/modules/login/controllers/login.php
/application/modules/login/models/login.php
/application/modules/login/views/login_form.php
controller/login.php code
class Login extends CI_Controller{
public function index(){
//load login form view
}
public function authenticate(){
$model = $this->load->model('login'); //tried with Login
$model->validate(); //shows error here
}
}
/views/login_form.php
<form name='LoginForm' method='post' action='/login/authenticate'>
/models/login.php
class Login extends CI_Model{
public function validate(){
echo $this->input->post('EmailId');
echo $this->input->post('Pword');
}
}
output:
got error indicating undefined method Login::validate()
When created validate() method in controller Login it works. But it shouldn’t happen.. even though I’m loading a model with name Login why it points to Login Controller.
Can anyone could help me out. The way I did is it correct? Suggestions welcomed…
You are loading and accessing your model incorrectly. Take a look at the documentation for more examples.
Change your
authenticate()method to: