我已经安装了 FOSCommentBundle,一切都可以按预期显示输入注释,但我想为每个实体显示 1 个线程,所以我有很多不同 url 的计划,比如:/planning/id。但是,每当我在 plan/1 中发表评论时。我在线程实体中创建了一个永久链接。但是当我想进入计划/2 时,它会显示计划/1 线程的评论,并且不会为计划/2 创建另一个永久链接。
我不明白我做错了什么。因此,如果您对我的问题有任何线索,我将不胜感激。
我创建了 2 个实体:
<?php
namespace Simon\CommentBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\CommentBundle\Entity\Comment as BaseComment;
use FOS\CommentBundle\Model\SignedCommentInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity
*/
class Comment extends BaseComment implements SignedCommentInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* Thread of this comment
*
* @var Thread
* @ORM\ManyToOne(targetEntity="Simon\CommentBundle\Entity\Thread")
*/
protected $thread;
/**
* Author of comment
*
* @ORM\ManyToOne(targetEntity="Simon\UserBundle\Entity\User")
* @var User
*/
protected $author;
public function setAuthor(UserInterface $author)
{
$this->author = $author;
}
public function getAuthor()
{
return $this->author;
}
public function getAuthorName()
{
if (null === $this->getAuthor()) {
return 'Anonymous';
}
return $this->getAuthor()->getUsername();
}
}
<?php
namespace Simon\CommentBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\CommentBundle\Entity\Thread as BaseThread;
/**
* @ORM\Entity
* @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
*/
class Thread extends BaseThread
{
/**
* @var string $id
*
* @ORM\Id
* @ORM\Column(type="string")
*/
protected $id;
}
我只是按照文档在我的计划树枝视图上显示评论:
{% extends "layout.html.twig" %}
{% block content %}
<h2>Planning de {{app.user.name}}</h2>
<div class="row">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Lundi</th>
<th>Mardi</th>
<th>Mercredi</th>
<th>Jeudi</th>
<th>Vendredi</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Responsable</th>
{% for i in 1..5 %}
{% set assigned_user = null %}
{% for user in users if user.planningday == i%}
{% set assigned_user = user %}
{% endfor %}
<td>
{% if not assigned_user is null %}
<a href="{{path('fos_user_profile_show_name', {'username':assigned_user.username})}}"> {{assigned_user.name}} {{assigned_user.lastname}}</a>
{% endif %}
</td>
{% endfor %}
</tr>
<tr>
<th scope="row">Description</th>
{% for i in 1..5 %}
{% set assigned_user = null %}
{% for user in users if user.planningday == i%}
{% set assigned_user = user %}
{% endfor %}
<td>
{% if not assigned_user is null %}
{{assigned_user.planningcontent}}
{% endif %}
</td>
{% endfor %}
</tr>
</tbody>
</table>
<a href="{{path('planningsub', {id:planning.id})}}">Inscription</a>
</div>
<div class="row">
{% include 'FOSCommentBundle:Thread:async.html.twig' with {'id': 'foo'} %}
</div>
{% endblock %}