页面控制器或实体控制器?(Controllers by page or controllers by entity?)

编程入门 行业动态 更新时间:2024-10-21 03:44:59
页面控制器或实体控制器?(Controllers by page or controllers by entity?)

我正在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.

更多推荐

本文发布于:2023-04-29 01:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334534.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   实体   页面   Controllers   controllers

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!