Zend framework 如何在向每个实例传递不同参数时重用paginationControl部分

Zend framework 如何在向每个实例传递不同参数时重用paginationControl部分,zend-framework,zend-paginator,Zend Framework,Zend Paginator,我使用paginationControl部分,并通过第4个参数传递参数,以允许我对“筛选”结果进行分页。这很好,但我希望能够对所有分页实例使用相同的分部,即使它们使用不同的参数 e、 g.“财产”按卧室数量过滤 在的视图脚本中的分页控件实例中提供第四个参数 array('beds' => '$beds') array('location' => '$location') 并用在部分 $this->beds $this->location 而“客户机”是按位置过滤的

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

e、 g.“财产”按卧室数量过滤

在的视图脚本中的分页控件实例中提供第四个参数

array('beds' => '$beds')
array('location' => '$location')
并用在部分

$this->beds
$this->location
而“客户机”是按位置过滤的

在的视图脚本中的分页控件实例中提供第四个参数

array('beds' => '$beds')
array('location' => '$location')
并用在部分

$this->beds
$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 partial,以防其他读者希望结果参数生成查询字符串

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

开始
以前的
下一个
终点

我想我明白了……

尝试以下方法:

<?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()是非常重要的部分。

您不需要使用:

$params = Zend_Controller_Front::getInstance()->getRequest()->getParams();
您只需要查询数组:

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

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

如果您显示部分变量,这将有所帮助。在不了解实现的情况下很难提供帮助。部分内容基本上是直接从Zend手册中获得的,但我还是会包括在内。我发现一个错误:)您的“开始”链接的第一个if()语句可能应该选中
isset($this->first)
,而不是
isset($this->previous)
group\u id参数是导致您出现问题的参数吗?这是你的第四个参数吗?@RockyFord re:error,我刚刚查阅了手册并进行了测试,$this->first和$this->last返回页码。当没有上一页或下一页时,此代码依赖于未定义的$This->previous和$This->next。我想我可以把它改为if($this->previous!=$this->current),但在Balance上,我认为它更容易理解。上面获得传递给partial的参数数组的访问权限的方法很好,取消控制器和动作参数的设置也很好。非常感谢。尽管我需要将附加参数(包括页面)表示为查询字符串,但我仍然支持我的案例。我接受了你的答案,因为它是有效的。我将包括我的完整部分以下作为一个不可接受的答案,因为我认为它值得包括在内,但我希望你得到信任。除此之外,非常感谢,我想知道为什么“上面的第一个if()是真正重要的部分”。您指的是选择是否基于至少存在一行数据来显示分页控件吗?或者还有别的什么吗?实际上是在收集当前url的if($this->pageCount)之后所做的$params收集url字符串中传递的所有内容,包括任何用户设置的参数。您只需构建一个与我不同的查询字符串。我倾向于依赖ZF默认值,您可以传递一个标准查询字符串。这完全取决于您使用哪种路由是的,我想使用没有标准查询字符串的ZF URL,但是过滤参数来自一个表单,GET方法总是构建一个标准的qury字符串,所以我只是在玩。