开发者

Should basic functions be in the controller or the model?

开发者 https://www.devze.com 2023-04-03 11:50 出处:网络
Should basic functions like this be part of the model or the controller? getLastPosts($number); getPost($id);

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号