Php 拉威尔集团管理路线
是否有一种方法可以对所有以Php 拉威尔集团管理路线,php,laravel,Php,Laravel,是否有一种方法可以对所有以admin/开头的路由进行干净分组? 我试过这样的方法,但当然没用: Route::group('admin', function() { Route::get('something', array('uses' => 'mycontroller@index')); Route::get('another', array('uses' => 'mycontroller@second')); Route::get('foo', arra
admin/
开头的路由进行干净分组?
我试过这样的方法,但当然没用:
Route::group('admin', function()
{
Route::get('something', array('uses' => 'mycontroller@index'));
Route::get('another', array('uses' => 'mycontroller@second'));
Route::get('foo', array('uses' => 'mycontroller@bar'));
});
与这些路线相对应:
admin/something
admin/another
admin/foo
当然,我可以直接在所有这些路由前面加上admin/
,但我想知道是否可以用我的方式来做
谢谢 不幸的是,没有。路线组不是设计成这样工作的。这是从Laravel文档中获取的 路由组允许您将一组属性附加到一组路由,从而使代码保持整洁 路由组用于将一个或多个筛选器应用于一组路由。你要找的是包裹 介绍捆绑包! 从外观上看,包裹就是你想要的东西。在bundles目录中创建一个名为“admin”的新bundle,并将其注册到application/bundles.php文件中,如下所示:
'admin' => array(
'handles' => 'admin'
)
handles键允许您更改捆绑包将响应的URI。因此,在这种情况下,对admin的任何调用都将通过该包运行。然后在新的bundle中创建routes.php文件,您可以使用(:bundle)占位符注册处理程序
// Inside your bundles routes.php file.
Route::get('(:bundle)', function()
{
return 'This is the admin home page.';
});
Route::get('(:bundle)/users', function()
{
return 'This responds to yoursite.com/admin/users';
});
希望这能给你一些想法。在
Laravel 4
中,你现在可以使用前缀
:
Route::group(['prefix' => 'admin'], function() {
Route::get('something', 'mycontroller@index');
Route::get('another', function() {
return 'Another routing';
});
Route::get('foo', function() {
return Response::make('BARRRRR', 200);
});
Route::get('bazz', function() {
return View::make('bazztemplate');
});
});
谢谢没有考虑捆绑包。仍然没有解决此问题,但是使用捆绑包?我要的是拉威尔3号