我正在开发一个 Zend Framework 应用程序,我刚刚使用http://tfountain.co.uk/blog/2010/9/9/vanity-urls-zend-framework/上的指南让我的虚荣路由工作,但我的分页不起作用,我找不到任何虚荣的 url 指南。
我的虚荣路线设置为/:username/:filter/:pag
',其中最后两个参数是可选的。页面显示正确,“/jaimerump/badges/2”将转到我的徽章的第二页,但分页器无法正常工作,因为它似乎无法确定下一页的 url 应该是什么。我正在使用每个 Zend 分页教程中的标准 paginationControl.phtml 文件,代码如下:
<?php if ($this->pageCount): ?>
<div class="paginationControl" id="paginationControl">
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url(array('page' => $this->previous)); ?>" id="previous">
< Previous
</a> |
<?php else: ?>
<span class="disabled">< Previous</span> |
<?php endif; ?>
<!-- Infinite Scroll doesn't use numbered page links -->
<!-- Next page link -->
<?php if (isset($this->next)): ?>
<a id="next" href="<?php echo $this->url(array('page' => $this->next)); ?>" >
Next >
</a>
<?php else: ?>
<span class="disabled">Next ></span>
<?php endif; ?>
</div>
<?php endif; ?>
不是返回“/jaimerump/badges/3”,而是$this->url()
返回“/”。我确信这与我的自定义路由类有关。我从 Tim Fountain 的教程中更改了 match 函数,并将类的名称更改为 VanityRouteUser 并将其放在我的模型文件夹中,但除此之外,一切都是相同的。匹配功能:
public function match( $path, $partial = false )
{
/* User profile routes are of form /:username/:filter/:page
Where filter can be haves, wants, badges, etc.
*/
if ($path instanceof Zend_Controller_Request_Http) {
$path = $path->getPathInfo();
}
$path = trim($path, $this->_urlDelimiter);
$pathBits = explode($this->_urlDelimiter, $path);
if ( count($pathBits) < 1 ) {
return false;
}
// check database for this user
$result = DB::call()->fetchRow('SELECT user_id
FROM users
WHERE username = ?', $pathBits[0]);
if ($result) {
// user found
$values = $this->_defaults;
$values['username'] = $pathBits[0];
$values['page'] = ( empty( $pathBits[2] ) )?1:$pathBits[2]; //if they didn't provide a page
// figure out which action based on second segment
$filter = $pathBits[1];
if( empty( $filter ) || $filter == 'default'
|| $filter == 'haves' || $filter == 'wants' ){
//Looking for user's haves, wants, or both
$values['action'] = 'index';
$values['filter'] = ( empty($filter) )?'default':$filter; //To catch the blank
}
else if( $filter == 'badges' ){
//Looking for user's badges
$values['action'] = 'badges';
}
else if( $filter == 'shelves' ){
//Looking for user's shelves
$values['action'] = 'shelves';
}
else{
//Must be a shelf id
$values['action'] = 'index';
$values['filter'] = $filter;
}
return $values;
}
return false;
}
是什么$this->url()
?我无法在 Zend Paginator 中找到 url 函数。我假设它正在调用路由类中的某个函数来尝试获取下一页的 url。它调用了什么函数,我必须重载它吗?