Symfony2 Gedmo Loggable版本和slug冲突?

时间:2015-10-01 08:22:04

标签: php symfony slug gedmo-loggable

当我在“名字”字段中使用Slug和Versioned时,我对Gedmo扩展有一点问题。

/**
 * @MongoDB\string
 * @Gedmo\Translatable
 * @Gedmo\Versioned
 */
protected $title;

/**
 * @Gedmo\Slug(fields={"title"})
 * @Gedmo\Versioned
 * @MongoDB\string
 */
protected $name;

在Gedmo LogFiles中没有出现flush slug。

我的结果:

'560ab47927987105118b4567' => 
object(Gedmo\Loggable\Document\LogEntry)[896]
  protected 'id' => string '560ab47927987105118b4567' (length=24)
  protected 'action' => string 'update' (length=6)
  protected 'loggedAt' => 
      ...
  protected 'objectId' => string '560ab323279871cf0b8b4569' (length=24)
  protected 'objectClass' => string 'Acme\AcmeBundle\Document\Foo'
  protected 'version' => int 2
  protected 'data' => 
    array (size=2)
      'title' => string 'I'm a new title' (length=23)
       // WHERE IS NAME FIELD ?
      'content' => string '<p>It's a new version</p>' (length=35)
  protected 'username' => string 'foo@barc.com' (length=20)

'560ab324279871cf0b8b456a' => 
object(Gedmo\Loggable\Document\LogEntry)[902]
  protected 'id' => string '560ab324279871cf0b8b456a' (length=24)
  protected 'action' => string 'create' (length=6)
  protected 'loggedAt' => 
      ...
  protected 'objectId' => string '560ab323279871cf0b8b4569' (length=24)
  protected 'objectClass' => string Acme\AcmeBundle\Document\Foo'
  protected 'version' => int 1
  protected 'data' => 
    array (size=3)
      'title' => string 'I'm a title' (length=18)
      'name' => null // First version name = null ???
      'content' => string '<p>Hey i'm a content</p>' (length=27)
  protected 'username' => string 'foo@bar.com' (length=20)

我找到了一个可能的解决方案,其中包括直接在setTitle中的slug:

/**
 * Set title
 *
 * @param string $title
 * @return self
 */
public function setTitle($title)
{
    $this->title = $title;
    $a = array('À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ð','Ñ','Ò','Ó','Ô','Õ','Ö','Ø','Ù','Ú','Û','Ü','Ý','ß','à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ø','ù','ú','û','ü','ý','ÿ','A','a','A','a','A','a','C','c','C','c','C','c','C','c','D','d','Ð','d','E','e','E','e','E','e','E','e','E','e','G','g','G','g','G','g','G','g','H','h','H','h','I','i','I','i','I','i','I','i','I','i','?','?','J','j','K','k','L','l','L','l','L','l','?','?','L','l','N','n','N','n','N','n','?','O','o','O','o','O','o','Œ','œ','R','r','R','r','R','r','S','s','S','s','S','s','Š','š','T','t','T','t','T','t','U','u','U','u','U','u','U','u','U','u','U','u','W','w','Y','y','Ÿ','Z','z','Z','z','Ž','ž','?','ƒ','O','o','U','u','A','a','I','i','O','o','U','u','U','u','U','u','U','u','U','u','?','?','?','?','?','?');
    $b = array('A','A','A','A','A','A','AE','C','E','E','E','E','I','I','I','I','D','N','O','O','O','O','O','O','U','U','U','U','Y','s','a','a','a','a','a','a','ae','c','e','e','e','e','i','i','i','i','n','o','o','o','o','o','o','u','u','u','u','y','y','A','a','A','a','A','a','C','c','C','c','C','c','C','c','D','d','D','d','E','e','E','e','E','e','E','e','E','e','G','g','G','g','G','g','G','g','H','h','H','h','I','i','I','i','I','i','I','i','I','i','IJ','ij','J','j','K','k','L','l','L','l','L','l','L','l','l','l','N','n','N','n','N','n','n','O','o','O','o','O','o','OE','oe','R','r','R','r','R','r','S','s','S','s','S','s','S','s','T','t','T','t','T','t','U','u','U','u','U','u','U','u','U','u','U','u','W','w','Y','y','Y','Z','z','Z','z','Z','z','s','f','O','o','U','u','A','a','I','i','O','o','U','u','U','u','U','u','U','u','U','u','A','a','AE','ae','O','o');
    $this->setName(strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/','/[ -]+/','/^-|-$/'),array('','-',''),str_replace($a,$b,$title))));
    return $this;
}

0 个答案:

没有答案