所以我使用fzTag插件实现了Doctrine模型的“可标记”扩展。
在我的行动中我有类似的东西:
$this->pager = new sfDoctrinePager('BlogEntry',5);
$this->pager->setQuery(Doctrine::getTable('BlogEntry')->createQuery('a')->leftJoin('a.Tags t')->where('t.id = ?',$this->tag->getId()));
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
在我的模板中我使用:
<?php foreach ($blogentry->getTags() as $tag): ?>
<a href="<?php echo url_for('blog_tags',$tag) ?>"><?php echo $tag->getName() ?></a>
<?php endforeach; ?>
但是在Template $ blogentry-&gt; getTags()中只返回一个标签?我怎么能改变这个?
答案 0 :(得分:1)
要检索BlogEntries,但仍然读取它的所有标签,我通常使用子查询,它指向我正确的条目。
因此,在准备好您的查询之后,就像通常的BlogEntry列表一样,您只需将其添加到条件:
$query->where($query->getRootAlias().'.id IN (
SELECT b1.id FROM BlogEntry b1 LEFT JOIN b1.Tags t1
WHERE t1.id = ? )', $this->tag->getId());
当然,最好将它保存在BlogEntryTable类中。