在Laravel中不带URI前缀的前缀路由名称

编程入门 行业动态 更新时间:2024-10-28 14:29:53
本文介绍了在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::get,Route::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前缀的前缀路由名称

本文发布于:2023-11-09 15:25:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572725.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:前缀   不带   路由   名称   Laravel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!