Roberto .
Roberto .

Reputation: 21

using doctrine2 sluggable extension with silex

I'm running into a strange problem trying to use the doctrine2 extension sluggable and timestampable in silex.

First of all I've succeded to use doctrine2 with silex following this guide:

http://martinsikora.com/silex-doctrine2-orm

After that, using this other guide, I've add sluggable and timestampable listener to my entity manager:

http://silex-doctrine-extensions.readthedocs.org/en/latest/doctrine.html

Now in my entity I've got this problem:

if I use something like that:

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */

doctrine2 don't recognize my entity, I need to use:

@Entity instead of @ORM\Entity

But if I use @ORM\Entity gedmo seems to work but he said me that he can't find the sluggable or the timestampable field (modified, created etc..) and if I run orm:generate-entities doctrine2 don't find my entity.

If I use @Entity instead of @ORM\Entity everithing work fine, but when I add the gedmo annotation like:

use Gedmo\Mapping\Annotation as Gedmo;

@Gedmo\Timestampable(on="create")

The Entity gave me errors about the normal annotation like @Column(type="datetime")

I think the only way is to use the prefix @ORM\ like every example I find on internet, but with this prefix orm:generate-entities stop finding my entity.

In symfony2 I've not this problem, I use @ORM\ prefix and doctrine2 extension sluggable and timestampable like a charm, I run into this problem using Silex, that have no native support to doctrine2 orm, only dbal, so I use the following provider to use the nutwerk-orm-extension

If you guys have some idea, please share with me.

Upvotes: 2

Views: 2055

Answers (1)

Julio
Julio

Reputation: 1943

Did you added the Gedmo namespace in composer?

{
    "autoload": {
        "psr-0": {
            "Gedmo": "vendor/gedmo/doctrine-extensions/lib'"
        },
}

I use this extension with Silex:

https://github.com/dflydev/dflydev-doctrine-orm-service-provider

I add the provider and the subscriber:

//Setting Doctrine ORM
$app->register(new Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider, array(
    "orm.proxies_dir" => $app['db.orm.proxies_dir'],
    "orm.em.options" => array(
        "mappings" => array(
            array(
                "type" => "annotation",
                "namespace" => "Entity",
                "path" => 'my_path',
            )
        ),
    ),
));

//Setting Doctrine2 extensions

$timestampableListener = new \Gedmo\Timestampable\TimestampableListener();
$app['db.event_manager']->addEventSubscriber($timestampableListener);

It works for me but I have to add these "uses" in my entities:

namespace Entity;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\GeneratedValue;

/**
 * EntityPages
 *
 * @Table(name="pages")
 * @Entity(repositoryClass="Entity\Repository\PagesRepository")
 * @HasLifecycleCallbacks()
 */
class EntityPages
{
    /**
     * @var integer
     *
     * @Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false)
     * @Id
     * @GeneratedValue(strategy="IDENTITY")
     */
    private $id;

Upvotes: 4

Related Questions