【问题标题】:Sluggable Doctrine behavior for Zend Framework2Zend Framework2 的 Sluggable Doctrine 行为
【发布时间】:2016-12-04 00:37:44
【问题描述】:

我正在使用ZF2Doctrine2 和 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 行为似乎不起作用。

知道为什么会这样吗?

【问题讨论】:

    标签: php zend-framework doctrine-orm slug


    【解决方案1】:

    试试:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-13
      • 1970-01-01
      • 1970-01-01
      • 2014-03-31
      • 2013-07-08
      • 2014-06-12
      • 2018-09-29
      相关资源
      最近更新 更多