J'ai installé le StofDoctrineExtensionsBundle et j'ai du mal à le faire fonctionner.Symfony2 - StofDoctrineExtensionBundle
Voici ma config composer.json:
.....
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.2.*",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "1.2.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.2.*",
"symfony/monolog-bundle": "2.2.*",
"sensio/distribution-bundle": "2.2.*",
"sensio/framework-extra-bundle": "2.2.*",
"sensio/generator-bundle": "2.2.*",
"jms/security-extra-bundle": "1.4.*",
"jms/di-extra-bundle": "1.3.*",
"friendsofsymfony/user-bundle": "*",
"doctrine/doctrine-migrations-bundle": "dev-master",
"stof/doctrine-extensions-bundle": "[email protected]"
},
....
J'ai ajouté le paquet dans mon appKernel:
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
J'ai ajouté ce qui suit à mon config.yml:
stof_doctrine_extensions:
default_locale: en_US
orm:
default:
sluggable: true
sortable: true
Voici mon entité:
<?php
namespace SixString\PearBundle\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="icon")
* @ORM\HasLifecycleCallbacks()
*/
class Icon
{
....(other properties and getters/setters)
/**
* @var \datetime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
protected $created;
/**
* @param \datetime $created
*/
public function setCreated($created)
{
$this->created = $created;
}
Dans mon contrôleur je:
/**
* @Route("/admin/go")
*/
public function goAction(){
$icon = new \SixString\PearBundle\Entity\Icon();
$icon->setName("shawn");
$icon->setZip(12345);
$icon->setType("go");
$em = $this->getDoctrine()->getManager();
$em->persist($icon);
$em->flush();
}
Quand je charge/admin/go je reçois l'erreur suivante:
An exception occurred while executing 'INSERT INTO icon (name, zip, thumb, created, updated, createdBy_id) VALUES (?, ?, ?, ?, ?, ?)' with params ["shawn", 12345, "go", null, null, null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'created' cannot be null
Je ne sais pas si je manque une étape ou configuration mais j'ai lu la documentation plusieurs fois et je ne vois rien.
Essayez de supprimer la méthode setCreated –
Je l'ai testé sans l'origine mais je l'ai ajouté pour tenter de résoudre le problème ... Même résultat de toute façon –