[eluser]Tpojka[/eluser]
You didn't pass the data. Right way is view->controller->model.
You passed data from view with function
Code:
form_open('admin/clogin/process');
, but in controller you have to use same data too for passing it to model.
So it should be something like:
Code:
public function process(){
$username = $this->input->post('username', TRUE);
$password = $this->input->post('password', TRUE);
// Load the model
$this->load->model('Login_model');
// Validate the user can login
$result = $this->Login_model->validate($username, $password); // here you send data to model
// Now we verify the result
if(! $result){
// If user did not validate, then show them login page again
$this->index();
}else{
// If user did validate,
// Send them to members area
redirect('admin/admin');
}
}
, and in model you have to adopt those data in form of method arguments:
Code:
public function validate($username, $password){ // same data you have sent from controller
// Prep the query
$this->db->get_where('username', $username);
$this->db->get_where('password', $password);
// Run the query
$query = $this->db->get('username');
// Let's check if there are any results
if($query->num_rows() == 1)
{
// If there is a user, then create session data
$row = $query->row();
$data = array(
'username' => $row->username,
'password' => $row->password,
'validated' => true
);
$this->session->set_userdata($data);
return true;
}
// If the previous process did not validate
// then return false.
return false;
}
}
This should be the basic MVC principle and how is used in CI.
Check what have I changed and test it as well. I didn't read rest of the code.