Search code examples
phpsymfonyfoscommentbundle

FOSCommentBundle how to implement


Is there some examples to implement this? Don't show nothing on my page.

{% include 'FOSCommentBundle:Thread:async.html.twig' with {'id': 'foo'} %} 

I don't understand how to place this code and what will show on my page.

And when i place this on my config.yml

    assetic:
         bundles: [ "FOSCommentBundle" ]   

Creates an error:

Unrecognized option "assetic" under "fos_comment".

My configuration:

fos_comment: db_driver: orm class: model: comment: BackEndBundle\Entity\Comment thread: BackEndBundle\Entity\Thread

assetic: bundles: [ "FOSCommentBundle" ]


Solution

  • I assume you have configure the bundle and have created the require classes like this

    namespace AppBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    use FOS\CommentBundle\Entity\Comment as BaseComment;
    
    /**
     * @ORM\Entity
     * @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
     */
    class Comment extends BaseComment
    {
        /**
         * @ORM\Id
         * @ORM\Column(type="integer")
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        protected $id;
    
        /**
         * Thread of this comment
         *
         * @var Thread
         * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Thread")
         */
        protected $thread;
    }
    

    And Thread.php like this

    namespace AppBundle\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;
    }
    

    In your config.yml, you will now have something like this

    fos_comment:
        db_driver: orm
        class:
            model:
                comment: AppBundle\Entity\Comment
                thread: AppBundle\Entity\Thread
    

    run the following commands

    doctrine:cache:clear-metadata
    doctrine:schema:update --force
    

    After this you will have tables in the database for the entities Now include this at top of the template

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
    

    where you've included this

    {% include 'FOSCommentBundle:Thread:async.html.twig' with {'id': 'foo'} %}
    

    Clear both dev and prod cache after this step. PS: I have selected the doctrine ORM method