【问题标题】:Zend_Paginator: no page number on links on a page with no page number specified by the URLZend_Paginator:在没有由 URL 指定页码的页面上的链接上没有页码
【发布时间】:2010-07-29 17:03:10
【问题描述】:

如果不将 /1 粘贴到 url 上,是否可以更改 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,分页器会正确链接到其他页面,如果我转到 /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>

【问题讨论】:

  • 你能发布一下当你使用没有第1页的链接时分页器是如何显示的吗?我想我不明白......我有使用它的应用程序,我和你做的一样,一切正常......
  • 你为 zend_paginator 使用 viewhelper 吗?如果是这样,您可能也应该发布它。

标签: zend-framework zend-paginator


【解决方案1】:

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

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

所以在生成链接时分页器没有打印页码,当我更改路线并将 :page var 放入分页器时。最终路线是:

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

【讨论】:

  • 我也这样做了..但是我的分页不起作用..就像第一次加载页面时它会正确显示所有页码 url 但是当我点击任何 url 时 url 会随之改变页码但页面没有改变,它只显示第 1 页,并且所有页码的 url 都变得相同..如果您熟悉这个问题,请帮助..谢谢..
【解决方案2】:

尝试在路由器中为 :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)));

【讨论】:

  • 感谢您的建议,但这没有任何区别,它仍然没有附加页面。
  • 好的。我不认为我完全理解你的问题:第一句话或两句话不太有意义,所以我猜了一下我认为你的意思(笑)。你能澄清一点吗?
  • 使用它作为 url 规则,如果我通过 alpha/studio 进入,该页面上的分页会直接链接回该页面,并且不会链接到 alpha/studio/1 alpha/studio/2 之类的你会期望:s
  • mmm... 是的,但你不需要 /1 所以主要的 url 是 /alpha/studio (page 1) /alpha/studio/2 (page 2) /alpha/ studio/3(第 3 页)等
  • 这与第一页不工作无关。它是关于当你登陆 alpha/studio 时 zend_paginator 没有链接到其他页面,点击第 2 页不会带你到 alpha/studio/2 它会链接到 alpha/studio。
猜你喜欢
  • 1970-01-01
  • 2016-01-27
  • 2014-04-29
  • 2015-09-15
  • 1970-01-01
  • 2010-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多