Dmitry Dmitry - 4 months ago 12
PHP Question

Sluggable Doctrine behavior for Zend Framework2

I'm using

ZF2
,
Doctrine2
and Gedmo doctrine extensions.

My slug field code is:

/**
* @Gedmo\Slug
* @ORM\Column(length=128, unique=true)
*/
protected $slug;


In my
module.config.php
i have added following:

`'doctrine' => array(
'driver' => array(
'backend_entity' => array(
'class' =>'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'paths' => array(__DIR__ . '/../src/Backend/Entity')
),
'orm_default' => array(
'drivers' => array(
'Backend\Entity' => 'backend_entity',
)
)
),
'eventmanager' => array(
'orm_default' => array(
'subscribers' => array(
'Gedmo\Tree\TreeListener',
'Gedmo\Timestampable\TimestampableListener',
'Gedmo\Sluggable\SluggableListener',
'Gedmo\Loggable\LoggableListener',
'Gedmo\Sortable\SortableListener'
)
)
),
'authentication' => array(
'orm_default' => array(
'object_manager' => 'Doctrine\ORM\EntityManager',
'identity_class' => 'Backend\Entity\User',
'identity_property' => 'email',
'credential_property' => 'password',
'credential_callable' => function(Backend\Entity\User $user, $passwordGiven) {
if ($user->getPassword() == md5($passwordGiven."salt")){
return true;
} else {
return false;
}
},
),
),
),`


When i'm creating new entity, i have got error 'slug cannot be null', thus sluggable behavior seems does not work.

Any idea why does it happen?

Answer

Try:

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