0

I've been trying to use the gedmo sluggable behavior for Doctrine2 on a ZF2 RC2 application using MongoDB but always end up with an error saying that Doctrine can't find the annotation even though its listener has suscribed to the event manager in the config file.

Here's the exact error message i get :

[Semantical Error] The annotation "@Gedmo\Mapping\Annotation\Slug" in property Application\Document\Place::$login does not exist, or could not be auto-loaded.

My module.doctrine-mongo-odm.local.php file contains the following regarding this issue :

[...]
'eventmanager' => array(
    'odm_default' => array(
        'subscribers' => array(
            'Gedmo\Sluggable\SluggableListener'
        )
    )
),
[...]

I know the SluggableListener is loaded by just putting a pretty die; in the __construct() so that means the autoload works.

Now in the Place document i make use of the slug on the login property via annotations just like that :

<?php
namespace Application\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM
 ,  Gedmo\Mapping\Annotation as Gedmo;


/** @ODM\Document(collection="places") */
class Place
{
[...]
/**
 * @ODM\String
 * @Gedmo\Slug(fields={name})
 */
private $login;

/** @ODM\String */
private $name;
[...]

What am i missing there ? Thanks for your help !

jhuet
  • 396
  • 2
  • 11

1 Answers1

2

You'll need to register any extra annotations, not just add listeners. Use the following key in the Mongo module config:

'configuration' => array(
    'odm_default' => array(
        'annotations'        => array(), // array('Annotation\Namespace\' => '/../annotation/path')
    )
),
chalasr
  • 12,971
  • 4
  • 40
  • 82
superdweebie
  • 1,576
  • 14
  • 23
  • Ok thanks @superdweebie that makes sense, however i can't figure out the right data to put there. I tried a bunch different things but didn't get much success. My best shot was this try i guess but it didn't work : `'Gedmo\Mapping\Annotation' => 'vendor/gedmo/doctrine-extensions/lib/Gedmo/Mapping/Annotation'` . Any idea ? – jhuet Aug 07 '12 at 07:58
  • I haven't set up l3pp4rd's DoctrineExtensions with DoctrineMongoODMModule myself, but I'm suprised that didn't work for you. Annotations use their own autoloader, so you might need to use the full path (??) Use the __DIR__ constant to help you out. If that doesn't work, log an issue on github and we'll look into it further. Ping @Ocramius – superdweebie Aug 07 '12 at 22:10
  • I did play with ``__DIR__`` but did not get more success and i'm sure the directory i passed is correct. That's weird, i've dug into the code a bit and got to : ``DoctrineMongoODMModule\Service\ConfigurationFactory::createService()`` where i found a call to ``AnnotationRegistry::registerAutoloadNamespaces($options->getAnnotations());`` and here the annotation dir retrieved from ``getAnnotations()`` looks like what i put in the configuration file shown in my last comment. – jhuet Aug 08 '12 at 12:28
  • @jhuet Sorry about the problems you are experiencing. I've just submitted some pull requests over on github that should hopefully cleanup annotation loading. – superdweebie Aug 08 '12 at 22:22
  • No problem @superdweebie ; it's still beta stage :) Thanks a lot for your help anyway ! I'll check it out as soon as it's merged. – jhuet Aug 09 '12 at 08:15
  • Okay, this has been solved - thanks ! More details [here](https://github.com/doctrine/DoctrineMongoODMModule/issues/27). – jhuet Aug 10 '12 at 10:28