9

好的,routes.php我使用的完整文件......我刚刚将它粘贴在这里: http: //pastebin.com/kaCP3NwK

路由.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/newsnews发送到action_index...但由于某种原因它没有到达那里并返回404

4

2 回答 2

5

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

实际上我的namespace寄存器是Admin\Models,所以将它设置'model' => 'Admin\Models\\News',为我的 404 问题

于 2013-01-08T16:22:17.640 回答
3

路由按照注册的顺序进行评估,因此 (:any) 路由应该在最后。您正在(我认为)被发送到 admin@index - 如果尚未定义该功能,这就是您收到 404 的原因。

于 2013-01-04T20:37:54.343 回答