[英]Laravel 4: Add username to every route url
如何在网址中添加用户名?
示例:www.domain.com/feeds/用户名
我想将用户名添加到每个路由网址。
::路线::
Route::get('feeds', array('before' => 'auth', 'as' => 'feeds', 'uses' => 'FeedsController@getFeedsPage'));
::控制器::
class FeedsController extends BaseController {
public function getFeedsPage() {
return View::make('feeds.index');
}
}
提前致谢。
迈克尔。
您可以尝试以下方法,声明如下路由(注意{username}
):
Route::get('feeds/{username}', array('before' => 'auth', 'as' => 'feeds', 'uses' => 'FeedsController@getFeedsPage'));
宣布class
:
class FeedsController extends BaseController {
// Use a parameter to receive the username
public function getFeedsPage($username) {
// You may access the username passed via route
// inside this method using $username variable
return View::make('feeds.index')->with('username', $username);
}
}
现在,您可以使用如下所示的URI
:
www.domain.com/feeds/username1
www.domain.com/feeds/michaelsangma
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.