0

我正在使用 paginationControl 部分,并通过第四个参数传递参数以允许我对“过滤”结果进行分页。这很好,但我希望能够对所有分页实例使用相同的部分,即使它们将使用不同的参数。

例如,“属性”按否过滤。卧室

在...的视图脚本中的分页控件实例中给出第四个参数

array('beds' => '$beds')

并用于部分...

$this->beds

而“客户”按位置过滤

在...的视图脚本中的分页控件实例中给出第四个参数

array('location' => '$location')

并用于部分...

$this->location

如何最好地做到这一点?我可以将第 4 个参数作为键和值的数组访问,并遍历数组并在 paginationControl 部分中为 url 视图帮助程序构建参数,如果我可以弄清楚如何访问该数组。但是,也许这不是采取的方法。

谢谢。

编辑:

这是我用来输出评论中要求的分页控件的部分内容。

    <div class="pagination">
      <div class="pages">

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

          <!-- Previous page link -->
          <?php if (isset($this->previous)): ?>
                <a href="<?= $this->url() . "?" . http_build_query(array('group_id' => $this->group_id, '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="<?= $this->url() . "?" . http_build_query(array('group_id' => $this->group_id, 'page' => $page)); ?>"><?= $page; ?></a>
              <?php else: ?>
                  <span class="current"><?= $page; ?></span>
              <?php endif; ?>
          <?php endforeach; ?>

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

          <!-- Last page link -->
          <?php if (isset($this->next)): ?>
                <a href="<?= $this->url() . "?" . http_build_query(array('group_id' => $this->group_id, 'page' => $this->last)); ?>">End</a>
          <?php else: ?>
              <span class="disabled">End</span>
          <?php endif; ?>
      </div>
    </div>

更新:

我接受了 RockyFords 解决方案,因为它回答了在分页控件部分实例化中访问通过第四个参数传递的参数的基本问题。但是,我将完整的 fina 部分包含在此处,以防其他读者希望结果参数生成查询字符串。

<div class="pagination">
  <div class="pages">
 <?php 
   $params = Zend_Controller_Front::getInstance()->getRequest()->getParams();
   unset($params['controller']);
   unset($params['action']);
 ?>


  <?= $this->first ?> 
  <!-- First page link -->
  <?php if (isset($this->previous)): ?>
        <a href="<?= $this->url() . "?" . http_build_query(array_merge($params , 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="<?= $this->url() . "?" . http_build_query(array_merge($params , 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="<?= $this->url() . "?" . http_build_query(array_merge($params , array('page' => $page))); ?>"><?= $page; ?></a>
      <?php else: ?>
          <span class="current"><?= $page; ?></span>
      <?php endif; ?>
  <?php endforeach; ?>

  <!-- Next page link -->
  <?php if (isset($this->next)): ?>
        <a href="<?= $this->url() . "?" . http_build_query(array_merge($params , 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="<?= $this->url() . "?" . http_build_query(array_merge($params , array('page' => $this->last))); ?>">End</a>
  <?php else: ?>
      <span class="disabled">End</span>
  <?php endif; ?>

4

2 回答 2

1

我想我明白了...

尝试类似:

<?php
if ($this->pageCount) :
    //you need to add each of the request parameters to url
    $params = Zend_Controller_Front::getInstance()
                    ->getRequest()->getParams();
    //remove the system parameters, $this->url will put them back
    unset($params['module']);
    unset($params['controller']);
    unset($params['action']);
    ?>
    <div class="paginationControl">         
                    <!--First Page Link -->
                    <?php if (isset($this->first)): ?>
                        <a href="<?php
                echo $this->url(array_merge($params, array('page' => $this->first)))
                        ?>">
                            &lt; First</a>
                    <?php else : ?>
                        <span class="disabled">&lt; First</span>
                    <?php endif ?>

                    <!--Previous Page Links-->
                    <?php if (isset($this->previous)) : ?>
                        <a href="<?php
                echo $this->url(array_merge($params, array('page' => $this->previous)))
                        ?>">
                            &lt; Prev</a>
                    <?php else : ?>
                        <span class="disabled">&lt; Prev</span>
                    <?php endif ?>
                <!--truncated ...-->

使用与此类似的分页控件,您将能够将任何用户设置的参数传回 url。上面的第一个 if() 是非常重要的部分。

于 2012-07-25T05:48:33.687 回答
0

你不需要使用这个:

$params = Zend_Controller_Front::getInstance()->getRequest()->getParams();

您只需要查询数组:

$array = Zend_Controller_Front::getInstance()->getRequest()->getQuery();

这将使您不必取消设置变量,因为您将获得一个仅包含查询字符串的漂亮数组:)

于 2012-10-29T14:04:37.870 回答