[eluser]zlatiborac[/eluser]
I know this is the newbie question of the decade, but I don't count my self in the newbie category and still have difficulties in understanding what goes where.
Until the early morning hours last night I used models
only for work with database, querying-collecting-working with data from databases. But then, since I am in one big project of mine, while talking with one more experienced developer I realized that something in my logic is wrong. I heavily rely on Controller to do all the work (meaning preparing all the data for View to display it), but when I saw him doing some stuff I noticed that 80% of work I did in Controller he did in Model.
Here is one method from the Controller
Code:
function doLogin(){
//uchitaj potrebne biblioteke
$this->load->library('encrypt');
$this->load->library('form_validation');
//prihvat podataka sa forme
$username = $this->input->post('username');
$password = $this->input->post('password');
//hass lozinke
$passHashed = dohash($password);
//query nad tabelom users
$query = $this->db->query("SELECT * FROM users WHERE username = '$username' AND password = '$passHashed'");
//proveriti da li postoji user i pass
if($query->num_rows() !=0){
$this->session->set_userdata('loggedin', 'yes');
$this->session->set_userdata('name', $username);
redirect ('admin_auth/loggedIn');
}
else
{
redirect ('/');
}
}
function isLoggedIn(){
if($this->session->userdata('loggedin') == 'yes'){
//$this->loggedIn();
return TRUE;
}
else
{
redirect ('/');
}
}
Now I will dislocate that SQL query in my Model, but, he is moving isLoggedIn also to a Model.
I need help on this. I am afraid that I will get stuck later on in my work and all this work, time and effort will go into vain