On Dec 12, 2008, at 7:32 AM, Julian102 wrote:
I think I was confused because a lot of the beginner tutorials I
have read
use methods like fetchAll and update in the controller. So I made the
mistake of thinking that the controller is where the action happens
and the
model was some sort of data access layer. Whereas now it makes sense
that
the work should happen in the model itself.
Right. I don't want to say one "never" calls data-access methods
directly from the Controller code, because there are exceptions to
every rule. If you have a Model whose data and behavior that always
maps exactly to that of a Table, then there's no immediate benefit to
adding another class layer in there, just for the sake of aesthetics.
But that case is uncommon (except in oversimplified examples used in
tutorials). Your Model should provide methods for higher-level
actions related to the work specific to your application.
Even when your Controller could do its job through simple calls
directly to the Table class, it's practically inevitable that the
complexity of that job will become gradually more complex over the
life of that application, until you wish you had encapsulated it in a
Model class, instead of littering your Controller with business rules.
Regards,
Bill Karwin