【发布时间】:2012-12-19 01:43:58
【问题描述】:
好的,我使用的完整 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'
));
管理员配置:
...
'models' => array(
'news' => array(
'title' => 'News',
'single' => 'news',
'model' => 'AdminModels\\News',
),
...
链接生成器:
@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
控制器/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;
}
因此,当访问 http://example.com/admin/news 时,news 被发送到 action_index... 但由于某种原因它没有到达那里并返回 404
【问题讨论】:
-
您的捆绑包是否已注册以处理路由? http://mysite.com/admin 是否加载您的索引页面? laravel.com/docs/routing#bundle-routes
-
@ChrisHendry 是的,默认情况下一切正常......我已经在捆绑文件中添加了一个新路由器,一个用于上传图像的路由,效果很好
-
如果您使用匿名函数调试并在路由中返回,它仍然是 404 吗? (不试图指向控制器/方法)
-
如果 Laravel 找不到路由,它会返回比服务器更漂亮的错误。你得到的是 Laravel 404 还是服务器的 404?
-
我收到了 Laravel 的 404 错误...如果它更像是一个 apache url 重写问题,那会更容易解决...我很确定 :D
标签: php laravel http-status-code-404 laravel-routing