2013-06-04 104 views
0

我想在我的项目中使用zend paginator。 我有问题 - 当我尝试在新闻控制器中使用paginator时,我在索引控制器上的paginator中有链接!zend paginator无效的网址

<?php 

class NewsController extends Zend_Controller_Action 
{ 
    /** 
    * 
    * @var Model_News_Gateway 
    */ 
    protected $_newsGateway; 

    protected $_newsPerPage = 10; 

    public function init() 
    { 
     $this->_newsGateway = new Model_News_Gateway(); 
    } 

    public function indexAction() 
    { 
     $crit = new ExtZF_Model_Criteria(); 

     $crit->addWhere('active', true); 
     $crit->addDescOrderBy('publish_date'); 

     $paginator = new Zend_Paginator($this->_newsGateway->getPaginatorAdapter($crit)); 
     $paginator->setCurrentPageNumber($this->_getParam('page', 0)); 
     $paginator->setItemCountPerPage($this->_newsPerPage); 

     $this->view->paginator = $paginator; 
    } 

鉴于

$this->paginationControl($this->paginator, 'Sliding', '_partials/paginator/default.phtml'); 

而且在默认

<?php if ($this->pageCount && count($this->pagesInRange) > 1): ?> 
<!--noindex--> 
<div class="paginationControl"> 
    (<?= $this->firstItemNumber ?>-<?= $this->lastItemNumber?>/<?= $this->totalItemCount ?>) 
     <?php if (isset($this->previous)): ?> 
    <a href="<?php echo $this->url(array('page' => $this->previous)); ?>"> 
     &lt; <?= $this->translate('previous') ?> 
    </a> | 
     <?php else: ?> 
    <span class="disabled">&lt; <?= $this->translate('previous') ?></span> | 
     <?php endif; ?> 

     <?php foreach ($this->pagesInRange as $page): ?> 
      <?php if ($page != $this->current): ?> 
    <a href="<?php echo $this->url(array('page' => $page)); ?>"> 
        <?php echo $page; ?> 
    </a> | 
      <?php else: ?> 
       <?php echo $page; ?> | 
      <?php endif; ?> 
     <?php endforeach; ?> 

     <?php if (isset($this->next)): ?> 
    <a href="<?php echo $this->url(array('page' => $this->next)); ?>"> 
     <?= $this->translate('next') ?> &gt; 
    </a> 
     <?php else: ?> 
    <span class="disabled"><?= $this->translate('next') ?> &gt;</span> 
     <?php endif; ?> 
</div> 
<!--/noindex--> 
<?php endif; ?> 

我试图为不相同的控制器使用一个默认的分页程序,但我一直有一个像/指数分页程序链接/索引/页/ 2。 我需要链接像/新闻/索引/页面/ 2 但我总是有链接/索引/索引/页面/ 2 现在我在新闻管制员。我不明白为什么它不起作用。

回答

0
<? 
//Ужасный хак, мне стыдно за него 
$controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName(); 

function replaceController ($search, $replace, $text) 
{ 
    $pos = strpos($text, $search); 
    $secondPos =strpos ($text, $search, $pos+1); 
    if ($secondPos !== false) { 
    return $pos !== false ? substr_replace($text, $replace, $pos, strlen($search)) : $text; 
    } else { 
     return $text; 
    } 
} 
?>