2013-03-23 109 views
0

我使用的Kohana 3.3,並具有以下目錄結構的設置(+號是指一個文件夾,•是指一個文件):Kohana的路線和分頁

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

對於「應用程序管理員」模塊我有以下路線定義:

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 

該W沒有問題的orks。我安裝了一個分頁模塊(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 ] 

我在做什麼錯?

感謝, ž

+1

什麼URL是分頁嘗試呼叫?你有沒有嘗試添加一個默認的控制器給你的管理路線? – xylar 2013-03-24 00:12:09

+0

所有分頁所做的只是將「page = x」添加到查詢字符串中,所以如果URL是http:// localhost/admin/locations,那麼分頁將具有「http:// localhost/admin/locations?page = 2" 。 – zoltalar 2013-03-24 14:03:30

+0

'localhost/admin/locations'是否工作,'localhost/admin/locations?page = 2'失敗? – xylar 2013-03-24 17:01:12

回答

0

我結束了每個控制器的「管理」模塊中專門設置了一個途徑,並提供了一個默認的「控制器」的值,例如:

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

它做到工作,現在分頁工作正常。我認爲「管理員」的「全能」路線會爲我做到這一點。