我为Translation
使用了Knp \ DoctrineBehaviors,为Sluggable
使用了StofDoctrineExtensionsBundle。如何通过缓存和区域设置检查slug
的唯一性?我想让slug看起来像这样:
for EN: /contacts
for PT: /pt/contacts
for PT (if duplicate): /pt/contacts-1
for ES: /es/contacts
但是现在,我有了这个数据库filter_node_translation
实体\ FilterNode.php :
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
/**
* @ORM\Table(name="filter_node")
* @ORM\Entity()
*/
class FilterNode
{
use ORMBehaviors\Translatable\Translatable;
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(name="id", type="integer")
*/
protected $id;
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
}
FilterNodeTranslation :
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Table(name="filter_node_translation")
* @ORM\Entity()
*/
class FilterNodeTranslation
{
use ORMBehaviors\Translatable\Translation;
/**
* @var string
*
* @ORM\Column(type="string", nullable=true)
*/
protected $sluggable;
/**
* @var string
*
* @Gedmo\Slug(fields={"sluggable"})
* @ORM\Column(type="string", nullable=true)
*/
protected $slug;
/**
* @return string
*/
public function getSluggable()
{
return $this->sluggable;
}
/**
* @param string $sluggable
*/
public function setSluggable($sluggable)
{
$this->sluggable = $sluggable;
}
}
答案 0 :(得分:0)
我找到了解决方案。 Gedmo sluggable有其他配置选项&#34; unique_base&#34;。
看起来像这样:
class FilterNodeTranslation
{
/**
* @var string
*
* @Gedmo\Slug(updatable=true, unique=true, unique_base="locale", fields={"sluggable"})
* @ORM\Column(type="string")
*/
protected $slug;
}