再生lug原则2 [英] Regenerating slug Doctrine2

查看:151
本文介绍了再生lug原则2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为在Doctrine2安装Sluggable扩展之前创建的实体的挽留,如下所述:重新生成slug ,但是当我将其设置为空字符串或null时,不会将其置为空。

I'm trying to regerate slug for entities that I've created prior to install Sluggable extension for Doctrine2 as it's explained here: Regenerating slug, but when I set it to empty string or null, does not regerate it, it simply sets as null.

我在做什么错?

实体:

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;

/**
* @ORM\Entity
* @ORM\Table(name="product")
*/
class Product
{

/**
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=200)
 * @Assert\NotBlank()
 */
protected $name;

/**
 * @ORM\Column(type="text")
 * @Assert\NotBlank()
 */
protected $description;

...

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

public function getSlug()
{
    return $this->slug;
}
public function setSlug($slug)
{
    $this->slug = $slug;

}
}

然后我尝试这样: / p>

And then I try this:

$repository = $this->getDoctrine()->getRepository('CommonBundle:Product');
$product = $repository->findOneBy(array("id"=>1));
$product->setSlug('');
$em = $this->getDoctrine()->getEntityManager();
$em->persist($product);
$em->flush();


推荐答案

我知道发生了什么。您可能正在使用旧版本的原则扩展,大概是版本2.1.0。如果您正在使用Symfony 2.0.X开发,那就是推荐的版本。检查你的deps文件,你可能有这样的东西:

OK. I know what is happening. You are probably using an older version of the Doctrine Extensions, probably version 2.1.0. That would be the case if you are developing with Symfony 2.0.X as that is the version which was recommended. Check your deps file, you probably have something like:

[gedmo-doctrine-extensions]
    git=http://github.com/l3pp4rd/DoctrineExtensions.git
    version=v2.1.0

那些扩展的旧版本不支持文档中描述的行为(如果空白则重新生成slug)。您需要升级您的扩展版本,但这可能意味着您可能必须将您的Doctrine版本升级到2.2,而不是真的确定。

Those older versions of the extensions don´t support the behaviour described in the documentation (regenerate slug if it is empty). You would need to upgrade your version of the extensions, but this may mean that you may have to upgrade your Doctrine versions to 2.2, not really sure.

这篇关于再生lug原则2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆