Laravel 调试 404 路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14160202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel debugging 404 routes
提问by Alex
Ok, the full routes.php
file that I use... I just pasted it here: http://pastebin.com/kaCP3NwK
好的,routes.php
我使用的完整文件......我只是把它粘贴在这里:http: //pastebin.com/kaCP3NwK
routes.php
路由文件
//The route group for all other requests needs to validate admin, model, and add assets
Route::group(array('before' => 'validate_admin|validate_model'), function()
{
//Model Index
Route::get('admin/(:any)', array(
'as' => 'admin_index',
'uses' => 'admin@index'
));
administrator config:
管理员配置:
...
'models' => array(
'news' => array(
'title' => 'News',
'single' => 'news',
'model' => 'AdminModels\News',
),
...
links generator:
链接生成器:
@foreach (Config::get('administrator.models') as $key => $model)
@if (Admin\Libraries\ModelHelper::checkPermission($key))
<?php $key = is_numeric($key) ? $model : $key; ?>
<li>
{{ HTML::link(URL::to_route('admin_index', array($key)), $model['title']) }}
</li>
@endif
@endforeach
controllers/admin.php
控制器/admin.php
public function action_index($modelName)
{
//first we get the data model
$model = ModelHelper::getModelInstance($modelName);
$view = View::make("admin.index",
array(
"modelName" => $modelName,
)
);
//set the layout content and title
$this->layout->modelName = $modelName;
$this->layout->content = $view;
}
So, when accessing http://example.com/admin/news
the news
is sent to action_index
... but for some reason it doesn't get there and it returns 404
所以,当访问http://example.com/admin/news
将news
被发送到action_index
......,但由于某种原因,它不到达那里和返回404
采纳答案by Alex
Notice that I defined the following 'model' => 'AdminModels\\News',
请注意,我定义了以下内容 'model' => 'AdminModels\\News',
when actually my namespace
register was Admin\Models
, so setting it to 'model' => 'Admin\Models\\News',
for my issue for the 404
实际上我的namespace
寄存器是Admin\Models
,所以将它设置'model' => 'Admin\Models\\News',
为我的 404 问题
回答by J.T. Grimes
Routes are evaluated in the order that they're registered, so the (:any) route should be last. You're being sent (I think) to admin@index -- if that function isn't defined yet, that's why you're getting a 404.
路由按照注册的顺序进行评估,因此 (:any) 路由应该放在最后。您(我认为)被发送到 admin@index —— 如果该功能尚未定义,这就是您收到 404 的原因。