【发布时间】:2014-04-22 03:09:49
【问题描述】:
如何从 blog.tags 中选择单个标签?我正在尝试从 blog.tags 属性链接单个标签。现在,当我将鼠标悬停在单个标签上时,我会看到一组标签,而不是单个标签。
标签
将鼠标悬停在一个标签上时的一组标签:
我正在为所有博客使用 for 循环,它是 twig 文件中的属性。我需要能够在 blog.tags 字段中的每个标签上进行选择以链接它,我该如何设置?
树枝文件
{% for blog in pagination %}
{% for tag in blog.tagsArray %}
<p>Tags: <span class="highlight"><a href="{{ path('AcmeDemoBundle_tag', { 'tag': tag }) }}">{{ tag }}</a></span></p><br><br>
{% endfor %}
{% endfor %}
实体
/**
* @var string
*
* @ORM\Column(name="tags", type="text")
*/
private $tags;
/**
* Set tags
*
* @param string $tags
* @return Blog
*/
public function setTags($tags)
{
$this->tags = $tags;
return $this;
}
/**
* Get tags
*
* @return string
*/
public function getTags()
{
return $this->tags;
}
控制器
public function indexAction($tag = null)
{
$em = $this->getDoctrine()->getManager();
$blogs = $em->getRepository('LSHealthFitnessBundle:Blog')
->getBlogs();
$tags = $em->getRepository('LSHealthFitnessBundle:Blog')
->getTags();
$postTags = $em->getRepository('LSHealthFitnessBundle:Blog')
->getPostsByTags($tag);
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$blogs,
$this->get('request')->query->get('page', 1)/*page number*/,
5/*limit per page*/
);
return array(
'blogs' => $blogs,
'tags' => $tags,
'postTags' => $postTags,
'pagination' => $pagination,
);
}
列表格式:(每个答案响应)
【问题讨论】:
标签: symfony tags doctrine twig