Saturday, October 1, 2011

Re: Fat Model Skinny Controlller? Is this really correct?

I'm certainly no expert but my understanding is that the placing as much logic in the model as possible is the best way as many controllers can use the same model and often many controller methods save/edit/delete model data.

For example, if you want to store a serializaed array into the db, if the logic to serialize the array is placed into the controller you would have to serialize the value everywhere that the model is saved.  If you have ten functions in the controller that save the model then you would have to repeat the code ten times.

However, if the code to serialize the array is placed in the model instead you only have to write the code once and can prety much forget about it from then on.  Also when you come to refactor your code you only have to change the code in one place, not in every controller using the model

It adhears to the DRY (Don't Repeat Yourself) principle and will make your life easier and hopefully less buggy.

At least that is my understanding.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: