0

我已经按照http://framework.zend.com/manual/en/zend.paginator.usage.html的分页教程

我已经成功地为我的网站实现了分页,但我对分页的 URL 输出不满意。第 2 页的示例网址:

http://www.example.com/posts/index/page/2

我想要的是删除index并拥有http://www.example.com/posts/page/2

为什么index在访问时包含this->url(在链接教程中的 my_pagination_control.phtml 中)?

有没有办法优雅地展示posts/page/2?甚至只是posts/2

4

2 回答 2

4

我觉得前面的答案不够,我给我的。首先,您可以在您的路由器中添加一个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' 的情况下,将以这种方式打印 url:

/CONTROLLER-NAME/page/5

在'paginator2'的情况下,url将以这种方式打印:

/CONTROLLER-NAME/5

显然,您看到CONTROLLER-NAME的将是您编写的控制器的名称。

于 2011-11-26T15:36:37.637 回答
0

你可以这样做:在你的 htaccess 文件中

    
重写引擎开启
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    重写规则 ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]

参考链接:http: //framework.zend.com/manual/en/zend.controller.router.html 希望对您有所帮助

于 2011-11-26T15:11:41.577 回答