當建設應用程序,最好的方式來決定什麼去哪裏。你怎麼知道什麼功能放在什麼控制器和模型。例如,我正在構建一個基於位置的應用程序。用戶可以發佈不同的內容,然後在一定距離內向其他用戶展示。此外,每個用戶都將擁有自己的配置文件頁面,該頁面將顯示該用戶發佈的所有內容,而不管位置。最好的方式來組織應用程序?....(MVC設計模式)
所以我有模特這樣
class UserModel extends BaseM{
get_user($uid);
get_all_users();
edit_user($new_data);
delete_user($uid);
add_user($new_user);
get_user_articles($uid);
get_user_reviews($uid);
get_user_foo($uid);
}
class ArticleModel extends BaseM{
get_article($aid);
get_all_articles();
add_article($new_article);
delete_article($aid);
}// similar to ReviewModel, and other models
class LocalModel extends BaseM{
get_local_articles($zip_code, $range);
get_local_reviews($zip_code, $range);
get_local_foo($zip_code, $range);
}// holds all location related functions
正如你所看到的,我集中在的usermodel一切都處理一個用戶(需要用戶ID),一切都處理位置(需要郵遞區號)在localModel,然後一切都有自己的模型。
我想知道什麼是最好的方法來弄清楚什麼去了哪裏,有沒有像這種東西的經驗法則?
這取決於你使用的是什麼框架(如果有的話)。大多數框架的MVC解釋和實現都不相同。 – 2009-12-06 23:52:23