Should basic functions be in the controller or the model?
Should basic functions like this be part of the model or the controller?
getLastPosts($number);
getPost($id);
I am trying to improve my webdevelopment and the quality of my programming. It seems开发者_StackOverflow社区 I can use both protected functions in the controller and functions in the model for this purpose.
I also sometimes see getPostbyTag, getIdbyName, getPostbyID, are these Cakephp automagic functions? Where can I read about them? I would love to use GetRecipebyId functions, since I am not even sure if I should use ->read or a very long find('all') with condition.
http://book.cakephp.org/view/1025/findAllBy (equivalent for find('all')) and http://book.cakephp.org/view/1026/findBy (find('first')); http://book.cakephp.org/view/1028/field if you get one to get a single value.
If you want to define your own getLastPost(), put it in the model.
getPostbyTag, getIdbyName, getPostbyID are not Cake automagic functions (AFAIK)
I usually don't mind a long find('all'). Unless you use the same find() alot, a long find('all') is still faster than making a model function.
They should always be in the model, so that other models and controllers can use them too.
精彩评论