关于laravel 5 路由的参数uses

WBOY
Release: 2016-06-06 20:18:59
Original
1528 people have browsed it

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

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

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

回复内容:

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

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

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

控制器动作模式
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>
Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!