Zend_Paginator:页面上的链接没有页码,URL没有指定页码

时间:2010-07-29 17:03:11

标签: zend-framework zend-paginator

没有粘贴/ 1到一个网址是否有更改Zend_Paginator接近URL?目前用户前往/ aaron / studio。然后,用户应点击分页并开始访问URL,例如:/ aaron / studio / 2

我有这条规则:

$router->addRoute('studios/page',   new Zend_Controller_Router_Route(':id/studio/:page',array('module' => 'default', 'controller' => 'studio', 'action' => 'view')));

如果我去/ aaron / studio / 2,Paginator正确链接到其他页面,如果我转到/ aaron / studio它没有链接到其他页面,只是它的页面。

我需要以某种方式让Paginator知道它的位置,即使URL中没有页面也是如此。

如果有帮助的话,请提供我的控制器代码:

      $page   = $this->_getParam('page', 1);
      $from   = ($page * $this->clips_per_page) - $this->clips_per_page;
      $count   = Model_Clip::load_by_type(array('type' => 'studio_id', 'values' => $object->id, 'to' => 0, 'to' => COUNT_HIGH, 'count' => 1, 'order' => 'd.views DESC'));
      $paginator = Zend_Paginator::factory($count);
      $paginator->setItemCountPerPage($this->clips_per_page);
      $paginator->setCurrentPageNumber($page);
  $paginator->setPageRange(25);
  $this->view->paginator = $paginator;

编辑,根据要求提供我的观点:

<?php if (count($this->paginator) && $this->paginator->count() > 1): ?>
    <?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml', array('translate' => $this->translate)); ?>
<?php endif; ?>

和部分

<div class="pagination-control" style="width: auto; text-align: center; margin: 0 auto">
    <div style="width: auto;">

        <!-- First page link -->
        <?php if (isset($this->previous)): ?>
              <a href="<?php echo $this->url(array('page' => $this->first)); ?>">Start</a> |
        <?php else: ?>
               <!--  <span class="disabled">Start |</span>  -->
        <?php endif; ?>

        <!-- Previous page link -->
        <?php if (isset($this->previous)): ?>
              <a href="<?php echo $this->url(array('page' => $this->previous)); ?>"> Previous</a> |
        <?php else: ?>
             <!--  <span class="disabled"> Previous |</span> -->
        <?php endif; ?>

        <!-- Numbered page links -->
        <?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: ?>
                <span class="chosen"><?php echo $page; ?></span>
            <?php endif; ?>
        <?php endforeach; ?>

        <!-- Next page link -->
        <?php if (isset($this->next)): ?>
              | <a href="<?php echo $this->url(array('page' => $this->next)); ?>">Next </a> |
        <?php else: ?>
             <!--  <span class="disabled">| Next |</span> -->
        <?php endif; ?>

        <!-- Last page link -->
        <?php if (isset($this->next)): ?>
              <a href="<?php echo $this->url(array('page' => $this->last)); ?>">End</a>
        <?php else: ?>
             <!--  <span class="disabled">End</span> -->
        <?php endif; ?>
        <p>
        &nbsp; Page <?php echo $this->current; ?> of <?php echo $this->last; ?>
        </p>

    </div>
    <p class="clear"></p>
</div>

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,我只是发现问题出在路线上。 首先我指定了这样的路线:

$router->addRoute(
'projects',
    new Zend_Controller_Router_Route('/:lang/projects/:category/', 
        array('lang' => 'en',
           'module' => 'index',
           'controller' =>'projects',
           'action' =>'index'
        )
    )
);

因此,在生成链接时,paginator没有打印页码,当我更改路径并将:page var paginator工作时。最后的路线是:

$router->addRoute(
'projects',
    new Zend_Controller_Router_Route('/:lang/projects/:category/:page', 
        array('lang' => 'en',
           'module' => 'index',
           'controller' =>'projects',
           'action' =>'index',
               'page'   => 1
        )
    )
);

答案 1 :(得分:0)

尝试为路由器中的:page提供默认值1

http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.standard (向下滚动到“变量默认值”)

$router->addRoute('studios/page',   
    new Zend_Controller_Router_Route(':id/studio/:page',
          array('module' => 'default', 'controller' => 'studio', 'action' => 'view'),
          array('page' => 1)));