symfony: fzTag-Pugin, Doctrine: retrieve Tags in template
So im Using the fzTag plugin which implements a "taggable" extension to Doctrine models.
In My Action i have something like:
$this->pager = new sfDoctrinePager('BlogEntry',5);
$this->pager->setQuery(Doctrine::getTable('BlogEntry')->createQuery('a')->leftJoin('a.Ta开发者_开发问答gs t')->where('t.id = ?',$this->tag->getId()));
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
and in my Template i use:
<?php foreach ($blogentry->getTags() as $tag): ?>
<a href="<?php echo url_for('blog_tags',$tag) ?>"><?php echo $tag->getName() ?></a>
<?php endforeach; ?>
But in the Template $blogentry->getTags() returns just one Tag? How can i change this?
To retrieve BlogEntries, but still read all it's tags, I usually use subquery, which points me to proper entries.
So, after having your query prepared, like for the usual BlogEntry list, you just add this where condition:
$query->where($query->getRootAlias().'.id IN (
SELECT b1.id FROM BlogEntry b1 LEFT JOIN b1.Tags t1
WHERE t1.id = ? )', $this->tag->getId());
Of course, it's best to keep it in your BlogEntryTable class.
精彩评论