I've been developing a web application using CodeIgniter.
I've also implemented all the functions following the MVC structure, but I am not sure whether I've confused myself so far...
If I use the functions from the model in the view, is that violating the MVC pattern? Is this considered as the view talking to the model?
Let me show some codes:
One from my controller:
public function loader($page){
#load pages if these settings will be loaded for sure
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$this->load->helper('url');
$this->load->library('session');
$this->load->model('app_model');
$this->load->model('app_user_model');
$this->load->view('app/header');
$this->load->view($page);
$this->load->view('app/footer');
}
One from my model:
public function submit_login($username, $pass){
//try to login, if the login credentials are correct, set the user session to username.
$this->db->select("name, PersonName");
$this->db->where("name", $username);
$this->db->where("pass", $pass);
$result = $this->db->get("members");
if ($result->num_rows() > 0){
foreach($result->result() as $user){
$this->session->set_userdata('user_name', $user->PersonName);
$this->session->set_userdata('user', $user->name);
}
return 1;
}return 0;
}
Partial view:
$is_login = $this->app_user_model->is_loggedin();
if($is_login){
//if user is logged in, prompt to log out
echo "Welcome back ".$this->session->userdata['user_name'].".";
echo anchor(base_url('profile/logout'), "logout" );
echo "<br/>";
}else{
echo validation_errors();
//if user is not logged in, ask to log in first
echo form_open('profile/login');
$user_name = array(
'maxlength' => '25',
'size' => '55',
'style' => 'width:30%; margin-left:5%',
'name' => 'username',
);
//get the date
echo "<div class='user_name_input'>";
echo "Username(email)";
echo form_input($user_name, '', 'class="user_name"');
echo "</div>";
In this case, I called is_loggedin() from the user_model..
Am I following the MVC pattern correctly?
Thanks for helping.