【发布时间】:2017-02-13 22:08:39
【问题描述】:
laravel 路由文件 web.php 中的“@”符号究竟代表什么
例如:Route::get('/', 'HomeController@index');?请不要告诉我这段代码是什么,我已经知道了。但问题是为什么@符号??
'@' 符号不是方法,但索引是。那么这个@符号的名称是什么,它到底是做什么的?我只是想知道为什么??? @ 符号。
【问题讨论】:
-
"at"... "HomeController" 表示将要使用的控制器,然后“at”功能...“at index function”。所以,我们将“HomeController@index”翻译成“我想要 HomeController 的 index 函数”。
-
AFAIK 它的唯一目的是将控制器类名与控制器方法名分开。也可以使用冒号或任何其他在类名/命名空间中不可用的字符,但选择了 at 符号。
-
来自 Router.php:
Now we can split the controller and method out of the action string so that we can call them appropriately on the class. This controller and method are in in the Class@method format and we need to explode them out then use them.。为什么@符号?询问开发人员,他们是选择它的人。 -
@JeffLambert 非常感谢!!这是我所期待的答案,所以我现在明白了。再次感谢。