3

如果不将 /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>
4

2 回答 2

2

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

$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
        )
    )
);
于 2011-08-29T16:18:57.747 回答
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)));
于 2010-08-05T07:36:04.943 回答