views:

90

answers:

3

What makes a good MVC model in CodeIgniter. What my 'user' model does now is basically using the same active record functions from the database library. The only difference is that you don't need to specify the database table and just do:

$this->usermodel->where('username','test'),
$user = $this->usermodel->get();

This feels kinda awkward, since its not making it 'a lot easier'.

Another way I thought of was making the user model like an user object with a load function. But this is not efficient when loading more than 1 user.

Can I get some tips from you guys? Thanks.

A: 

I think 'a lot easier' comes in when you are working with large sets of data, and have many complex queries to make. As I understand it, if you are working on something that is relatively simple, you can forego the model and make your db calls from within the controller. There isn't a 'best practice' per se, but rather personal preference.

The MVC architecture allows for better compartmentalizing of code, and can allow for better structure and re-use of code, but you needn't follow the MVC idea to the letter to accomplish many things -- again it comes down to preference.

stormdrain
I know what's the point of using the MVC design pattern. I was just asking for some tips about the model structure itself.
Jens
A: 

The point is to abstract all of your application logic into Models and use Controllers simply for 'controlling' your web interface and mediating between the web interface and the models.

The models are your program proper you should be able to pretty easily completely redesign the user interface without affecting the application models.

DRL