Welcome Guest, Not a member yet? Register   Sign In
Regarding OOP and MVC
#1

[eluser]greedyh4mster[/eluser]
Hiya everyone!

I just started using Codeigniter. There are a few concepts here that I have seen, through the codes of other Codeigniter developers. Below are several questions that I have. Hopefully, someone will help me out.

1)Regarding MVC.
I understand that the Model is a place where you put your database related functions. Views is a place where you will put the HTML. Controller is where you put the 'checking of user input', and redirecting codes.

For example (I am trying to build my own cms):

Member_Model.php:
Code:
class Account_model extends Model{
    function logout($user_id){
        if($this->db->update('user', array('token_cookie' => ''), array('user_id' => $user_id))){
            return TRUE;
        }
        return FALSE;
    }
}

view_members.php:
Code:
<div class="sidebar">
   <div class="logout">&lt;?php echo anchor('member/logout','Logout'); ?&gt;</div>
</div>

Member_Controller.php:
Code:
class Account extends Controller{
    function logout(){
        if($this->member_model->logout($user_id)){
            set_cookie('rememberme', '', 1);
            $this->session->sess_destroy();
            //redirect('user/login');        
        }
    }
}

Just to ensure that I have the right concept. The above code is correct right?
The controller should not contains any 'database related process' and should only have 'codes that are related to the process' right?

Following on my concept, I thought of the OOP. In codeigniter, the controller acts or is itself a 'webpage' where the user's input will go towards to. If that is the case, wouldnt be much more 'OOP' if I were to put my 'Member object' into a library instead of doing it in a controller?

I have checked out several cms here and realized that most of them have the common concept of: controller->library->model->View

So if I am to put my Member object into a library. Wouldn't it be better if I have the member library to handle the member objects, including 'database related process'. So the concept will end up like: controller->library->view

Then again. The Model will seem useless in the above concept, isnt it? But in the above concept, I assume that a library should be self-sufficient enough to handle an object (in my case: Members) which means a library should contains 'database related process' as well.

I understand that it is a bit confusing. but I will seriously require some help in clearing my doubts over these. Please kindly help me.

Thanks!!


Messages In This Thread
Regarding OOP and MVC - by El Forum - 03-28-2010, 06:30 AM
Regarding OOP and MVC - by El Forum - 03-28-2010, 09:19 AM
Regarding OOP and MVC - by El Forum - 03-28-2010, 09:31 AM
Regarding OOP and MVC - by El Forum - 04-20-2010, 12:39 PM
Regarding OOP and MVC - by El Forum - 05-20-2010, 07:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB