Zend Framework2 的 Sluggable Doctrine 行为
Sluggable Doctrine behavior for Zend Framework2
我正在使用 ZF2
、Doctrine2
和 Gedmo 学说扩展。
我的 slug 字段代码是:
/**
* @Gedmo\Slug
* @ORM\Column(length=128, unique=true)
*/
protected $slug;
在我的 module.config.php
中,我添加了以下内容:
`'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;
}
},
),
),
),`
当我创建新实体时,出现错误 'slug cannot be null',因此 sluggable 行为似乎不起作用。
知道为什么会这样吗?
尝试:
/**
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(name="slug", length=128, unique=true)
*/
protected $slug;
我正在使用 ZF2
、Doctrine2
和 Gedmo 学说扩展。
我的 slug 字段代码是:
/**
* @Gedmo\Slug
* @ORM\Column(length=128, unique=true)
*/
protected $slug;
在我的 module.config.php
中,我添加了以下内容:
`'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;
}
},
),
),
),`
当我创建新实体时,出现错误 'slug cannot be null',因此 sluggable 行为似乎不起作用。
知道为什么会这样吗?
尝试:
/**
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(name="slug", length=128, unique=true)
*/
protected $slug;