D
D
Dmitry Cherednichenko2014-07-09 23:58:54
Kohana
Dmitry Cherednichenko, 2014-07-09 23:58:54

How to properly configure the router for the pagination module in Kohana?

Good day!
Installed the pagination module for Kohana. It seems to be even.
But I can not properly configure the routes.
Here are all the routes that I have:

Route::set('default', '(<controller>(/<action>(/<id>)))')
  ->defaults(array(
    'controller' => 'main',
    'action'     => 'index',
  )); 
  
Route::set('products', '<products>/<id>-<url>', array('id' => '[0-9]+'), array('url' => '.+'), array('page' => '[0-9]+'))
  ->defaults(array(
    'controller' => 'products',
    'action'     => 'product',		
  )); 

Route::set('products', '(<products>(/<action>/<page>(/<id>)))/<page>', array('page' => '[0-9]+'))
  ->defaults(array(
    'controller' => 'products',
    'action'     => 'index',
  ));

Pagination set to Products controller on action_index
// пагинация
    $count = ORM::factory('product')->count_all();
    $content->pagination = Pagination::factory(array('total_items' => $count));
    $products = ORM::factory('product')
      ->limit($content->pagination->items_per_page)
      ->offset($content->pagination->offset)
      ->find_all();

Well, the config itself, just in case
<?php defined('SYSPATH') or die('No direct script access.');

return array(

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

);

Please help me set up the route.
At the moment I have this, but the links under the numbers are empty, more precisely, they lead to main_index :
6051fe41ce1544e5a207ac07c4b4cad3.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2014-07-10
@likeapimp

The links are empty because link building takes the current Route. You have the current default, because it matches any links that consist of 3 segments; and in general it should be the last one.
Plus, your routes are strange, there are 3 nuances 1. <variable> 2. (what may not be in the bracket) 3. everything else is just as it is

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question