[英]Namespaced routes not working in Laravel 5
I'm building an international website, therefore I managed to have URLs looking like /{language}/{other_stuff}
thank to some manipulation in RouteServiceProvider
我建立一个国际性的网站,所以我设法寻找有像URL
/{language}/{other_stuff}
感谢在某些操作RouteServiceProvider
/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function map(Router $router, Request $request)
{
$locale = $request->segment(1);
$this->app->setLocale($locale);
/**
* Internationalization routing system
*/
$router->group(['namespace' => $this->namespace, 'prefix' => $locale], function($router) use ($locale) {
if ($locale == 'en') require app_path('Http/routes_en.php');
elseif ($locale == 'el') require app_path('Http/routes_el.php');
});
}
Works like a charm. 奇迹般有效。 Every language will have his own route file, it's a choice.
每种语言都有自己的路径文件,这是一个选择。
Let's say we go to /en/
and you're an admin, I created another namespace within Http/route_en.php
to focus on the admin section : 假设我们转到
/en/
并且您是管理员,我在Http/route_en.php
创建了另一个命名空间,专注于管理部分:
Route::group(['namespace' => 'Admin', 'prefix' => 'admin'], function() {
Route::controller('', 'DashboardController');
Route::controller('brands', 'BrandsController');
Route::controller('contents', 'ContentsController');
Route::controller('downloads', 'DownloadsController');
Route::controller('news', 'NewsController');
Route::controller('products', 'ProductsController');
Route::controller('settings', 'SettingsController');
Route::controller('users', 'UsersController');
});
So now I should access easily sections such as /en/admin/brands
but it fails. 所以现在我应该轻松访问
/en/admin/brands
但它失败了。 I generate all my links dynamically thanks to the HTML class 由于HTML类,我动态生成所有链接
{!! HTML::linkAction('Admin\BrandsController@getIndex', 'Brands') !!}
The generation works fine when I go to /en/admin
which means Admin\\BrandsController@getIndex
is detected by this package, but when you click on it 当我转到
/en/admin
时,这一代工作正常,这意味着这个包检测到Admin\\BrandsController@getIndex
,但当你点击它时
Sorry, the page you are looking for could not be found.
I tested some stuff and when I just simply set the route outside group()
it works fine. 我测试了一些东西,当我只是在
group()
之外设置路由时它运行正常。
Route::controller('admin/brands', 'Admin\BrandsController');
What am I missing here ? 我在这里错过了什么? Shouldn't the HTML class and the routing system agree with each others ?
HTML类和路由系统不应该彼此一致吗? Is there any mistake I made ?
我犯了什么错误? Maybe there's an issue ?
也许有问题?
EDIT : I opened an issue for this problem on GitHub 编辑:我在GitHub上为这个问题打开了一个问题
So nobody tried to help me. 所以没有人试图帮助我。
After a few days, an issue and many tests I understood the problem by myself : you have to put the DashboardController
route at the end otherwise the routing system will take it first and ignore the other ones. 几天之后,一个问题和许多测试我自己理解了这个问题:你必须把
DashboardController
路由放在最后,否则路由系统将首先接受它并忽略其他路由。
/**
* Admin
*/
Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => 'is.admin'], function() {
Route::controller('news', 'NewsController');
Route::controller('brands', 'BrandsController');
Route::controller('products', 'ProductsController');
Route::controller('users', 'UsersController');
Route::controller('downloads', 'DownloadsController');
Route::controller('settings', 'SettingsController');
Route::controller('contents', 'ContentsController');
Route::controller('', 'DashboardController');
});
NOTE : Everything will seem alright in the route listing, and even in the HTML/Form packages, but it's not. 注意:在路由列表中,即使在HTML /表单包中,一切似乎都没有问题,但事实并非如此。
I let it here for anybody that would have similar problems. 我在这里为任何会遇到类似问题的人提出这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.