Zend的分页URL格式
问题描述:
我已经按照从http://framework.zend.com/manual/en/zend.paginator.usage.htmlZend的分页URL格式
我已经成功地实现分页为我的网站分页教程,但我不满意输出分页网址。 2页例如网址:
http://www.example.com/posts/index/page/2
我想什么是去除index
,只是有http://www.example.com/posts/page/2
为什么包括index
同时(在链接在my_pagination_control.phtml从教程)访问this->url
?
有没有办法优雅地显示posts/page/2
?甚至只是posts/2
?
答
我觉得以前的答案是不够的,我给我的。首先,你可以添加你bootstrap.php
路由器看起来像:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initRoutes()
{
$Router = Zend_Controller_Front::getInstance()->getRouter();
$Route = new Zend_Controller_Router_Route(
':controller/*',
array(
'controller' => 'index',
'action' => 'index'
)
);
$Router->addRoute('paginator1', $Route);
$Route = new Zend_Controller_Router_Route(
':controller/:page/*',
array(
'controller' => 'index',
'action' => 'index',
),
array(
'page' => '[0-9]+'
)
);
$Router->addRoute('paginator2', $Route);
}
}
,然后在你的视图这个简单的线路上使用:
echo $this->url(array('controller' => 'CONTROLLER-NAME', 'page' => 5), 'paginator1', TRUE);
echo $this->url(array('controller' => 'CONTROLLER-NAME', 'page' => 5), 'paginator2', TRUE);
在“paginator1”的情况下,链接将被打印以这种方式:
/CONTROLLER-NAME/page/5
在“paginator2”的情况下,URL将在这样进行打印:
/CONTROLLER-NAME/5
显然你看到的地方CONTROLLER-NAME
将是你写的控制器的名字。
答
你可以这样做: 在你的htaccess文件
RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L]
链接以供参考:http://framework.zend.com/manual/en/zend.controller.router.html 希望它可以帮助
刚刚添加了这个,工作! – binnyb
@binnyb如果它没有工作,我不会写:p –