FOSCommentBundle线程

时间:2017-07-29 14:01:17

标签: php symfony foscommentbundle

我已经安装了FOSCommentBundle,everythings按预期工作输入注释显示,但我希望每个实体显示1个线程,所以我有许多计划使用不同的url,如:/ planning / id。但每当我在计划/ 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 %}

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。

<div class="row">
    {% include 'FOSCommentBundle:Thread:async.html.twig' with {'id': 'planning'~planning.id} %}
</div>