在一个动作中使用 symfony && 学说 1.2,我尝试为用户显示排名最高的网站。
我做了:
public function executeShow(sfWebRequest $request)
{
$this->user = $this->getRoute()->getObject();
$this->websites = $this->user->Websites;
}
唯一的问题是它返回一个包含所有网站的 Doctrine 集合,而不仅仅是排名靠前的网站。
我已经设置了一个方法(getTopRanked()
),但如果我这样做:
$this->user->Websites->getTopRanked()
它失败。
如果有人有想法改变 Doctrine 集合以仅过滤排名靠前的。
谢谢
PS:我的方法看起来像(在 websiteTable.class.php 中):
public function getTopRanked()
{
$q = Doctrine_Query::create()
->from('Website')
->orderBy('nb_votes DESC')
->limit(5);
return $q->execute();
}