lundi 29 juin 2015

Unable to find slug [slug] as mapped property in entity Gedmo Doctrine Extensions


I am implementing the Gedmo Sluggable annotations in Symfony 2 and cannot get the slugs to generate at all and it throws a 500 error everytime I try to save the object.

I've tried creating a new object as well as updating an existing object that has a slug already defined.

// config.yml
stof_doctrine_extensions:
    default_locale: en_US
    orm:
        default:
            timestampable: true
            uploadable: true
            sluggable: true

Object class

// Journal.php
<?php
namespace Example\JournalBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Example\UserBundle\Entity\User;
use \DateTime;


/**
 * Class Journal
 * @package Example\JournalBundle\Entity
 *
 * @ORM\Entity(repositoryClass="Example\JournalBundle\Entity\JournalRepository")
 * @ORM\Table(name="journal", indexes={
 *     @ORM\Index(name="idx_created", columns={"created"}),
 *     @ORM\Index(name="idx_status", columns={"status"})
 * })
 */
class Journal
{
    /**
     * @var int
     *
     * @ORM\Column(type="integer", options={"unsigned"=true})
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var string
     *
     * @ORM\Column(type="string", length=100)
     */
    protected $title;

    /**
     * @Gedmo\Slug(fields={"title", "id"})
     * @ORM\Column(length=128, unique=true)
     */
    protected $slug;

    /**
     * @return mixed
     */
    public function getSlug()
    {
        return $this->slug;
    }

    /**
     * @param mixed $slug
     * @return $this
     */
    public function setSlug($slug)
    {
        $this->slug = $slug;
        return $this;
    }


}

controller

<?php
namespace Example\JournalBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Example\JournalBundle\Entity\Journal;

/**
 * Class JournalController
 * @package Example\JournalBundle\Controller
 *
 * @Route("/journals")
 */
class JournalController extends Controller
{
    /**
     * @Route("/slugify")
     * @Security("is_granted('IS_AUTHENTICATED_ANONYMOUSLY')")
     * @Template("ExampleJournalBundle::test.html.twig")
     */
    public function slugifyAction()
    {
        $em = $this->getDoctrine()->getManager();
        $user = $this->getUser();

        $journal = new Journal();
        $journal->setBody('this is the body');
        $journal->setTitle('this is the title');
        $journal->setPrivacy(1);
        $journal->setStatus(1);
        $journal->setType(1);
        $journal->setUser($user);
        $em->persist($journal);
        $em->flush();
    }
}

It throws the following error: Sluggable error Any ideas why sluggable is not working?


Aucun commentaire:

Enregistrer un commentaire