在Laravel中不带URI前缀的前缀路由名称 [英] Prefix route name without prefixing URI in Laravel

查看:502
本文介绍了在Laravel中不带URI前缀的前缀路由名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个命名空间'Front''Admin'.对于'Admin'命名空间,可以为所有路径加上admin.conrtoller.action作为前缀,但是对于'Front',我希望具有带前缀的路由名称而没有带前缀的URI.

I have two namespaces 'Front' and 'Admin'. For 'Admin' namespace it is OK to have all paths prefixed with admin.conrtoller.action, but for 'Front' I want to have prefixed route names without prefixed URIs.

Route::group(array('namespace' => 'Front'), function()
{
    Route::resource('franchising', 'FranchisingController', array('only' => array('index')));
});

这将为我生成franchising.index根名称和get 'franchising' URI.如何使该组中的所有资源生成路由名称,如front.franchising.index,但保留当前URI不变(即,不给其加上front/前缀).

This generates me franchising.index root name and get 'franchising' URI. How to make all resources in this group to generate route names like front.franchising.index, but leave current URIs without change (i.e. not prefixing it with front/).

我使用Laravel 4.2.

I use Laravel 4.2.

推荐答案

路由前缀主要用于为路径添加前缀.它还会在路由名称前加上前缀,这一事实只是使用Route::resource()时的一种附加行为.

Route prefix is mainly for prefixing the path. The fact that it also prefixes route names, is just an added behavior when using Route::resource().

编辑

在Laravel中,使用prefix路由组参数实际使用前缀绝对是不可能的.

It is definitely not possible with the actual prefixing, using a prefix route group parameter, in Laravel out of the box.

Route::resource()Route::controller()只是适合它们的少量实际用例的快捷方式.它们绝对不是适合所有情况的工具.如果需要对路由进行更多控制,建议使用Route::getRoute::post等手动指定路由.

Route::resource() and Route::controller() are only a shortcuts for small amount of real use cases, where they fit. They are definitely not tools that fits for everything. If more control over routes is needed, manually specifying routes with Route::get, Route::post and such is advisable.

这篇关于在Laravel中不带URI前缀的前缀路由名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆