phpzend-frameworkpaginationzend-paginator

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.


Solution

  • 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');
        }