如果特定符号,Symfony会为实体生成slug

时间:2016-03-10 09:28:36

标签: php symfony doctrine-orm

我有实体技能,并且有野外技能的场地slu and,当我创造技能并且写C ++时有slug = c OR如果创建C. - 有slug = c或者当创建C#时仍然有slug = c。我认为在Gedmo中有一些正则表达式。也许谁知道如何覆盖Gedmo slug或hot来解决这个问题?

use Gedmo\Mapping\Annotation as Gedmo;

/**
 * Skills.
 *
 * @ORM\Table(name="code_directory_skills")
 */
 class Skill
 {
use Timestampable;
/**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 * @Expose()
 * @Groups({"for_skill_by_id", "for_all_skills", "for_all_skills_extended"})
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="skill", type="string", length=255)
 * @Expose()
 * @Groups({"for_skill_by_id", "for_all_skills", "for_all_skills_extended"})
 */
private $skill;

/**
 * @Gedmo\Slug(fields={"skill"}, updatable=true)
 * @ORM\Column(name="slug", type="string", nullable=false)
 * @Groups({"for_skill_by_id", "for_all_skills", "for_all_skills_extended"})
 * @Expose()
 */
protected $slug;

我创建了监听器

namespace Artel\ProfileBundle\Listener;

use Gedmo\Sluggable\SluggableListener as BaseSluggableListener;

class SluggableListener extends BaseSluggableListener
{
public function __construct()
{
    $this->setTransliterator(array('\Artel\ProfileBundle\Util\Transliterator', 'transliterate'));
}
}

并在$ text中创建翻译器,然后在

中使用C ++
Urlizer::urlize($text, $separator) //have have C

类:

use Gedmo\Sluggable\Util\Urlizer;

class Transliterator
{
public static function transliterate($text, $separator = '-')
{
    $text = Urlizer::unaccent($text);
    return Urlizer::urlize($text, $separator);
}
}

我改变了

class Transliterator
{
public static function transliterate($text, $separator = '-')
{
    $text = Urlizer::unaccent($text);

    return $text; //have C++
}
}

但在DB中仍然只有slug = c

并配置此扩展程序:

stof_doctrine_extensions:
class:
    sluggable: Artel\ProfileBundle\Listener\SluggableListener
default_locale: "%locale%"
orm:
    default:
        timestampable: true
        sluggable:     true
        softdeleteable: true

Transliterator如何为sluggable启用特定符号?谁知道 ?当调试两次进入штсдфыыTransliterator

1 个答案:

答案 0 :(得分:0)

您可以定义自己的侦听器,并决定要为slugs应用哪个策略。见下面的链接。

https://github.com/Guite/MostGenerator/issues/241

Translator::translate中,您可以定义政策。