Peter
Peter

Reputation: 215

Zend Framework 1 Paginator change URL

I would like to change the URL from http://localhost/domain/index/index/page/1 to http://localhost/domain/page/1. I've already tried to change the routes, however, I've got some errors. This is my controller part:

$page=$this->_getParam('page',1);
$paginator = Zend_Paginator::factory($images->fetchAll($images->select()->order('id ASC')));
$paginator->setItemCountPerPage(24);
$paginator->setCurrentPageNumber($page);
$this->view->paginator=$paginator;

View Part:

<?php
   foreach($this->paginator as $record){
      echo $record['name'];
   }
?>

<?= $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>

As you can see I'm using standard 'pagination.phtml' file. Thanks a lot for your help.

Upvotes: 1

Views: 416

Answers (2)

Yazid Erman
Yazid Erman

Reputation: 1186

As an addition to @s-rupali's answer, and For those who does not know her structure for pagination, the other way would be to use this structure inside the routes.ini:

   $route = new Zend_Controller_Router_Route(
       'custom-text/:page',
    array(
        'controller' => 'index',
        'action'     => 'index',
        'page'     => 1
    ) 
);

$router->addRoute('new_pagination', $route);

Upvotes: 0

Rupali
Rupali

Reputation: 1078

You can create routes as mentioned below:

routes.flexi.type = "Zend_Controller_Router_Route"
routes.flexi.route = "custom-text/:page"
routes.flexi.defaults.module = "core"
routes.flexi.defaults.controller = "index"
routes.flexi.defaults.action = "index"
routes.flexi.defaults.page = 1
routes.flexi.reqs.page = \d+

This will work for below URL:

http://localhost/custom-text/2
http://localhost/custom-text/3

Default will be page 1 with below URL:

http://localhost/custom-text

Edit:

Create routes.ini in application/configs/ directory

In Bootstrap.php you need to instantiate routes as follows:

protected function _initRouter(){
        $routes = new Zend_Config_Ini('/application/configs/routes.ini', APPLICATION_ENV); //change path according to your project 
        $front = Zend_Controller_Front::getInstance();
        $front->getRouter()->addConfig($routes, 'routes');
    }

Upvotes: 1

Related Questions