zend paginator无效的网址

时间:2013-06-04 10:51:58

标签: zend-framework pagination

我尝试在我的项目中使用zend paginator。 我有问题 - 当我尝试在新闻控制器中使用paginator时,我在索引控制器上的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; ?>

我正在尝试使用一个默认的paginator来做不同的控制器,但我总是在/ index / index / page / 2这样的paginator中有链接。 我需要像/ news / index / page / 2这样的链接 但我总是有链接/索引/索引/页面/ 2 我现在在新闻控制器。我不明白为什么它不起作用。

1 个答案:

答案 0 :(得分: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;
    }
}
?>