Zend Framework 1 分页器更改 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'); ?>

如您所见,我使用的是标准 'pagination.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

编辑:

application/configs/ 目录中创建 routes.ini

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