Zend Framework 1 Paginator change URL


Zend Framework 1 Paginator change URL

我想将URL从http://localhost/domain/index/index/page/1更改为http://localhost/domain/page/1。我已经尝试改变路线,但是,我有一些错误。这是我的控制器部分:

$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;

视图部分:

<?php
   foreach($this->paginator as $record){
      echo $record['name'];
   }
?>
<?= $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>

您可以看到,我使用的是标准的"分页"。phtml"文件。非常感谢您的帮助。

您可以按照如下方式创建路由:

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+

这将适用于以下URL:

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

默认为第1页,URL如下:

http://localhost/custom-text
编辑:

创建routes.iniapplication/configs/目录

Bootstrap.php中,您需要实例化路由如下:

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

作为@s-rupali答案的补充,对于那些不知道她的分页结构的人,另一种方法是在routes.ini中使用这个结构:

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