我想将网址从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'); ?>
正如您所看到的,我正在使用标准&#39; pagination.phtml&#39;文件。非常感谢你的帮助。
答案 0 :(得分:1)
您可以按照以下说明创建路线:
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+
这适用于以下网址:
http://localhost/custom-text/2
http://localhost/custom-text/3
默认将是第1页,其中包含以下网址:
http://localhost/custom-text
修改强>
在routes.ini
目录
application/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');
}
答案 1 :(得分:0)
作为@ 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);