问题描述
laravel文档中有一个有关单动作控制器的主题:
A topic about single action controllers is in the laravel documentation:
https://laravel.com/docs/5.5/controllers#single -action-controllers
我的问题是,您将在哪里使用此控制器?如果您选择对所有控制器使用单一动作控制器,您将如何构造控制器?
My question is, what is the use case where you will use this controllers? How will you structure your controllers if you opt to use single action controllers for all your controllers?
推荐答案
Michale Dyrynda似乎在他的博客: https://dyrynda.com.au/blog/single-action-controllers-in-laravel
Michale Dyrynda seems to sum up the pupose of Single Action Controllers in his blog: https://dyrynda.com.au/blog/single-action-controllers-in-laravel
-
单个动作控制器是将简单功能包装到命名明确的类中的有效方法.
Single action controllers are an effective way to wrap up simple functionality into clearly named classes.
它们可以用在您不必遵循RESTful方法的情况下;注意不要在多个控制器之间为单个实体分开执行多个操作.
They can be used in instances where you're not necessarily following a RESTful approach; be careful not to separate multiple actions for a single entity across multiple controllers.
在以前可能将单个控制器用于多个静态页面的地方,可以考虑为每个静态页面使用单独的命名控制器.
Where you might have previously used a single controller for multiple static pages, you could consider separate named controllers for each static pages.
您可以向此类添加其他方法,但它们应与该控制器负责的单个操作有关.
You can add other methods to this class, but they should be related to the single action this controller is responsible for.
他还指出,仅当您只需要对实体执行单个操作时,才应使用这些内容:
He also states that, you should only use these when you only need a single action for an entity:
这篇关于在Laravel中,单一动作控制器的优势是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!