我正在使用paginationControl partial,并通过第4个参数传递参数以允许我对“已过滤”的结果进行分页。这工作正常,但我希望能够对所有分页实例使用相同的部分,即使它们将使用不同的参数。
e.g。 “属性”按否过滤。卧室
在...的视图脚本中的分页控件实例中给出第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>
更新
我接受了RockyFords解决方案,因为它回答了在分页控件partial的实例化中访问通过第4个参数传递的参数的基本问题。但是,我在这里包含了我的完整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; ?>
答案 0 :(得分: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)))
?>">
< First</a>
<?php else : ?>
<span class="disabled">< 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)))
?>">
< Prev</a>
<?php else : ?>
<span class="disabled">< Prev</span>
<?php endif ?>
<!--truncated ...-->
使用类似于此的分页控件,您将能够将任何用户设置参数传递回URL。上面的第一个if()是非常重要的部分。
答案 1 :(得分:0)
您不需要使用它:
$params = Zend_Controller_Front::getInstance()->getRequest()->getParams();
您只需要查询数组:
$array = Zend_Controller_Front::getInstance()->getRequest()->getQuery();
这将节省你不得不设置变量,因为你会得到一个只包含查询字符串的漂亮数组:)