Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter: what makes a good model

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.

like image 580
Jens Avatar asked Feb 05 '26 22:02

Jens


1 Answers

A good tip would be, not letting model an view talk with each other straight, you always(or when it's possible) have to use controller to do this kind of communication.

I've heard also the opinion that it's a bad practice to have logic inside your models...I don't know if this is true but it's a rule I have broken lots of times(if somebody knows more about the subject please correct me).

And of course always have in mind that model should be reusable , so I try to give general solution to some problems and not application specific...on the other hand controller seems to be the throwaway component so this is where you should do ugly stuff that will never be used in other projects...

Hope it helps a little

like image 151
rabidmachine9 Avatar answered Feb 07 '26 11:02

rabidmachine9



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!