我正在使用 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; ?>