Laravel调试404路由

时间:2013-01-04 15:41:50

标签: php laravel http-status-code-404 laravel-routing

好的,我使用的完整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

2 个答案:

答案 0 :(得分:4)

请注意,我定义了以下'model' => 'AdminModels\\News',

实际上我的namespace注册时间为Admin\Models,因此将其设置为'model' => 'Admin\Models\\News',以解决我的404问题

答案 1 :(得分:3)

路由按照它们注册的顺序进行评估,因此(:any)路由应该是最后一个。你被发送(我认为)给admin @ index - 如果那个函数还没有定义,那就是你得到404的原因。