0

paginationControl パーシャルを使用し、パラメーターを 4 番目のパラメーターに渡して、「フィルター処理された」結果をページ分割できるようにしています。それは正常に機能していますが、異なるパラメーターを使用する場合でも、ページネーションのすべてのインスタンスに対して同じパーシャルを使用できるようにしたいと考えています。

たとえば、「プロパティ」は no でフィルタリングされます。寝室

ビュースクリプトのページネーションコントロールのインスタンスに4番目のパラメータを与える...

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

部分的に使用されます...

$this->beds

一方、「クライアント」は場所によってフィルタリングされます

ビュースクリプトのページネーションコントロールのインスタンスに4番目のパラメータを与える...

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>

アップデート:

ページネーション コントロール パーシャルのインスタンス化で 4 番目のパラメーターを介して渡されたパラメーターにアクセスするという基本的な質問に答えるため、私は RockyFords ソリューションを受け入れました。ただし、別の読者が結果のパラメーターでクエリ文字列を生成する必要がある場合に備えて、完全なフィナ パーシャルをここに含めます。

<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 に答える