J'ai fait un site avec Symfony3 et du coup comme le plupart des dév Symfony j'utilise des bundles, aujourd'hui j'ai décidé d'installer la FosCommentBundle, aucun problème lors de l'installation et des configurations j'ai suivi le tutoriel sur github.
Mais lors de l'affichage d'une page où j'ai inclue les commentaires, la possibilité d'ecrire un commentaire, rien ne s'affiche. D'où viendrai le problème ?
AppKernel :
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new AppBundle\AppBundle(),
new YN\MarmitonBundle\YNMarmitonBundle(),
new FOS\UserBundle\FOSUserBundle(),
new FOS\RestBundle\FOSRestBundle(),
new FOS\CommentBundle\FOSCommentBundle(),
new JMS\SerializerBundle\JMSSerializerBundle($this),
];
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
public function getRootDir()
{
return __DIR__;
}
public function getCacheDir()
{
return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
}
public function getLogDir()
{
return dirname(__DIR__).'/var/logs';
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}
Création du Thread et Comment :
<?php
// src/AppBundle/Entity/Thread.php
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;
}
<?php
// src/AppBundle/Entity/Comment.php
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="MyProject\MyBundle\Entity\Thread")
*/
protected $thread;
}
Config de l'app :
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: fr
framework:
#esi: ~
translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
fos_user:
db_driver: orm
firewall_name: main
user_class: AppBundle\Entity\User
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%"
fos_comment:
db_driver: orm
class:
model:
comment: AppBundle\Entity\Comment
thread: AppBundle\Entity\Thread
{% include 'FOSCommentBundle:Thread:async.html.twig' with {'id': 'foo'} %}
<!DOCTYPE html>
<html lang="fr">
<head>
<title>Bienvenu sur Marmithon | Plus de 670000 recettes</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
//Pas intéressant le reste
Et sur ma page où j'ai inclue le bundle, rien ne s'affiche ... encore merci d'avance pour votre aide !
Le vrai courage n'est pas de savoir quand supprimer une vie, mais quand en épargner une.
Je n'ai pas d'erreurs sur le debug web, je ne pense pas que le template avant la balise Doctype ai un impact sur l'affichage que ce soit sous le Doctype ou dans le body rien ne s'affiche, je ne l'ajoute pas dans le layout mais dans une vue, ta réponse serai donc de mettre la template dans le controller ?
Le vrai courage n'est pas de savoir quand supprimer une vie, mais quand en épargner une.
Uncaught TypeError: $.get(...).error is not a function
at Object.get (bundles/foscomment/js/comments.js:85)
at Object.getThreadComments (bundles/foscomment/js/comments.js:103)
at bundles/foscomment/js/comments.js:525
at bundles/foscomment/js/comments.js:540
api/threads/foo/comments?permalink=http%253A%252F%252Flocalhost%253A8000%252Frecettes Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Merci mais j'ai refait le projet sur Symfony2, ma version sur laquelle je travaillais était la 3, et sa à marcher, je réessaierai plus tard mais sur symfony2 la manip marche, merci pour vos réponses. Il faudrai que FOS MAJ pour le commentBundle sous Symfo3.
Le vrai courage n'est pas de savoir quand supprimer une vie, mais quand en épargner une.
[SYMFONY3] FOSCommentBundle Config
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.