Home >Backend Development >PHP Tutorial >关于laravel 5 路由的参数uses

关于laravel 5 路由的参数uses

WBOY
WBOYOriginal
2016-06-06 20:18:591544browse

<code>Route::get('/login', ['uses' => 'LoginController@index']);

Route::get('/login', 'LoginController@index');

//请问这两种写法有区别?
//uses 是代表什么的?</code>

回复内容:

<code>Route::get('/login', ['uses' => 'LoginController@index']);

Route::get('/login', 'LoginController@index');

//请问这两种写法有区别?
//uses 是代表什么的?</code>

控制器动作模式
URL::action('LoginController@index')
这种方式是根据注册路由时 'uses' 参数,自动生成映射到控制器方法的uri
Route::controller('login','LoginController');
结果类似于:
Route::get('login',['uses'=>'LoginController@getIndex']);
Route::get('login/edit',['uses'=>'LoginController@getEdit']);
Route::post('login/edit',['uses'=>'LoginController@postEdit']);
2种写法没区别,uses常配合as使用,为控制器动作指定路由名称
Route::get('user/login', [

<code>'as' => 'login', 'uses' => 'LoginController@getIndex'</code>

]);
return redirect()->route('login');

要注意,uses,我当时看成user,浪费了很多时间,偏偏这两个都是不报语法错误的。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn