0

我尝试在我的项目中使用 zend 分页器。而且我有问题 - 当我尝试在新闻控制器中使用分页器时,我在索引控制器的分页器中有链接!

<?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; ?>

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

4

1 回答 1

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;
    }
}
?>
于 2013-06-05T04:12:02.877 回答