我正在Laravel建立一个自我管理的机构网站,其中包含一些动态内容,如:产品,新闻,用户等,我对控制器和最佳实践产生了怀疑。
虽然有些页面是完全静态的(关于,服务信息,...),但其他页面(如产品列表)是动态的。
我不确定是否必须按页面或实体创建控制器。 例如:
ProductController => shows the page for a single product ProductsController => shows the page for listing all the products SearchController => shows the page for searching products AboutController => shows the about page ServicesController => shows the page for listing services vs ProductsController => shows the page for single and multiple products, and the search products page PagesController / StaticController => shows all static pages (like "about" and "services")对此最好的方法是什么?
I'm building in Laravel a self managed institutional website with some dynamic content like: products, news, users, etc., and I came up with a doubt about controllers and best practices.
While some pages are fully static (about, services info, ...) others, like products listing, are dynamic.
I'm not sure if I have to create controllers by page or entities. Eg:
ProductController => shows the page for a single product ProductsController => shows the page for listing all the products SearchController => shows the page for searching products AboutController => shows the about page ServicesController => shows the page for listing services vs ProductsController => shows the page for single and multiple products, and the search products page PagesController / StaticController => shows all static pages (like "about" and "services")What is the best approach for this?
最满意答案
Controller将负责显示实体值。 所以你应该使用你的第二个例子,按实体控制。
例如,您有“显示我的静态网站”功能,这是一个功能,一个职责,所以一个类/控制器。 如果你为许多控制器划分它,那给你重复的代码。
Controller will be class responsible for displaying entity values. So You should use your second example, controllers by entity.
You have for example functionality "Show my static site", this is one functionality, one responsibility, so one class/controller. If you divide it for many controllers, that gave You duplicate code.
更多推荐
发布评论