2011-11-26 108 views
0

我已經按照從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

回答

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」的情況下,鏈接將被打印以這種方式:

/CONTROLLER-NAME/page/5 

在「paginator2」的情況下,URL將在這樣進行打印:

/CONTROLLER-NAME/5 

顯然你看到的地方CONTROLLER-NAME將是你寫的控制器的名字。

+0

剛剛添加了這個,工作! – binnyb

+0

@binnyb如果它沒有工作,我不會寫:p –

0

你可以這樣做: 在你的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 希望它可以幫助

+0

所以說我有很多控制器與分頁,並希望從每個排除'索引'。這仍然是排除它的理想方式嗎? – binnyb

+0

@binnyb接下來的建議是添加路由器。 –

+0

@AurelioDeRosa啊,優秀!我現在將研究如何使用這些。謝謝! – binnyb