【问题标题】:Kohana Routes and PaginationKohana 路线和分页
【发布时间】:2013-03-23 21:00:33
【问题描述】:

我使用的是 Kohana 3.3,并具有以下目录结构设置(+ 号表示文件夹,• 表示文件):

+ modules
  + app-admin
    + classes
      + admin
        • Companies.php
        • Users.php
        • Locations.php
    + i18n
    + views
  + app-front
    + classes
    + i18n
    + views

对于“app-admin”模块,我定义了以下路由:

Route::set('admin default', 'admin')
    ->defaults(array(
        'directory'  => 'admin',
        'controller' => 'authentication',
        'action'     => 'login'
    ));
Route::set('admin', 'admin/<controller>(/<action>(/<id>))')
->defaults(array(
    'directory'  => 'admin'
));

这些路由使我能够访问“管理员”控制器:

http://localhost/admin/companies
http://localhost/admin/companies/edit/2
http://localhost/admin/companies/add

这没有问题。我安装了一个分页模块(https://github.com/webking/kohana-pagination),它具有以下配置:

'admin' => array(
        'current_page'      => array('source' => 'query_string', 'key' => 'page'), // source: "query_string" or "route"
        'total_items'       => 0,
        'items_per_page'    => 2,
        'view'              => 'admin/_partials/pagination',
        'auto_hide'         => FALSE,
        'first_page_in_url' => FALSE,
    )

当我这样做时,我收到以下错误:

Kohana_Exception [ 0 ]: Required route parameter not passed: controller
SYSPATH\classes\Kohana\Route.php [ 599 ]

我做错了什么?

谢谢, Z

【问题讨论】:

  • 分页试图调用什么 URL?您是否尝试将默认控制器添加到您的管理路由?
  • 所有分页只是在查询字符串中添加“page=x”,所以如果 URL 是localhost/admin/locations,那么分页将有“localhost/admin/locations?page=2”。
  • localhost/admin/locations 是否有效,localhost/admin/locations?page=2 是否失败?
  • 这两个链接都可以正常工作,但是当分页链接被渲染时,它们“失去”了控制器,所以我没有 localhost/admin/locations?page=2 我有 localhost/admin ?page=2

标签: pagination routes kohana


【解决方案1】:

我最终为“admin”模块中的每个控制器设置了一个路由,并提供了一个默认的“controller”值:

Route::set('admin users', 'admin/users(/<action>(/<id>))')
    ->defaults(array(
        'directory'  => 'admin',
        'controller' => 'users', // Provided a default value for <controller>
        'action'     => 'index'
    ));

它完成了工作,分页现在工作正常。我认为“管理员”的“包罗万象”路线会为我做到这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 2012-03-31
    • 1970-01-01
    相关资源
    最近更新 更多