Thanks for the reply. I am trying to implement this concept in my project now.
But I ran into some design dilemma.
I have a model that has a set of methods (like a mgr component).
getBooks(),
updateBook(),
newBook(),
deleteBook(),
Where should I validate and how should I pass my data to the model?
1. Inside controller.
I do a mass attributes assignment in my controller, call model->validate() and then updateBook() with no parameters pass in.
2. Inside the model by parameter.
I pass the data to the model via an array, Eg. updateBook(array(…)) and call $this->validate() in the model.
3. Inside the model by $_POST[].
I get data by getting $_POST[] in my model method, validate and save.
All 3 methods has it’s pros and cons.
method 1.
pros - easy assignment, and validations.
cons - if I share my model’s method, the other developer must know to do assignment and validations before calling my model’s method.
- my controller is still quite fat.
method 2
pros - method signature is very clear.
cons - a problem if I have a huge attribute list to pass in as parameter.
method 3.
pros - easy assignment. no need to pass huge array to my model’s method.
cons - having $_POST in my model’s method will hinder code reusability.
Which method should I adopt to realize the Fat model Thin controller concept?