laravel 5.5 控制器名称应该是复数还是单数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48031176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
laravel 5.5 controller name should be plural or singular ?
提问by Mohsen Jalalian
what is the naming convention in laravel 5.5 for controllers . they should be singular or plural . I saw some people use singular and some people use plural for that . what is the correct form ?
Laravel 5.5 中控制器的命名约定是什么?它们应该是单数或复数。我看到有些人使用单数,有些人为此使用复数。什么是正确的形式?
回答by Sohel0415
回答by Md. Amirozzaman
You should follow those naming convention:
您应该遵循这些命名约定:
- Model Name should be singular e.g: 'Profile', not 'Profiles'
- Controller name should be singular with 'Controller' suffix e.g: 'ProfileController', not 'ProfilesController'
- Php class Name should be in 'StudlyCase' format e.g: 'TestClass'
- Php function Name should be in 'camelCase' format e.g: 'testFunction'
Class constants MUST be declared in all upper case with underscore separators; for example:
class Foo { const VERSION = '1.0'; const DATE_APPROVED = '2012-06-01'; }
- 模型名称应该是单数,例如:“配置文件”,而不是“配置文件”
- 控制器名称应该是带有“Controller”后缀的单数,例如:“ ProfileController”,而不是“ProfilesController”
- Php 类名称应采用“StudlyCase”格式,例如:“ TestClass”
- Php 函数名称应采用“camelCase”格式,例如:“ testFunction”
类常量必须全部使用下划线分隔符以大写形式声明;例如:
class Foo { const VERSION = '1.0'; const DATE_APPROVED = '2012-06-01'; }
Useful link:
有用的链接:
回答by learnjourney
Plural. Although the official laravel docs use singular for controller names, it is very well known that most of prominent laravel developers such as Jeffrey Way, Adam Wathan, Chris Fidao and many others uses plural for controller names that it sort of become the actual standard.
复数。虽然官方 Laravel 文档使用单数作为控制器名称,但众所周知,大多数著名的 Laravel 开发人员,例如 Jeffrey Way、Adam Wathan、Chris Fidao 和许多其他人使用复数作为控制器名称,这在某种程度上成为了实际标准。
You are far better off using plural so you feel less confusion when you watch their videos, read their blog posts.etc
您最好使用复数形式,这样您在观看他们的视频、阅读他们的博客文章等时就不会感到困惑