2015-06-30 53 views
3

在Symfony 2.5中使用MongoDB時,我遇到捆綁「a2lix/translation-form-b​​undle」的問題。我想我已經完成了一切,就像它在文檔中,但我有「所需的選項」類「缺失。」錯誤。Symfony 2,MongoDB + a2lix /翻譯形式束

我的產品:

/** 
* Class Product 
* @MongoDB\Document(repositoryClass="MyBundle\ProductBundle\Repository\ProductRepository") 
* @Gedmo\TranslationEntity(class="MyBundle\ProductBundle\Document\ProductTranslation") 
*/ 
class Product implements Translatable 
{ 

/** 
* @MongoDB\Id 
* 
*/ 
protected $id; 

/** 
* @MongoDB\String 
* @Gedmo\Translatable 
*/ 
protected $name; 

/** 
* 
* @MongoDB\ReferenceMany(targetDocument="MyBundle\ProductBundle\Document \ProductTranslation", mappedBy="object", cascade={"all"}) 
* 
*/ 
private $translations; 


public function __construct() 
{ 
    $this->translations = new ArrayCollection(); 
} 

public function __toString() 
{ 
    return $this->getName(); 
} 

/** 
* Get id 
* 
* @return id $id 
*/ 
public function getId() 
{ 
    return $this->id; 
} 

/** 
* Set name 
* 
* @param string $name 
* @return self 
*/ 
public function setName($name) 
{ 
    $this->name = $name; 
    return $this; 
} 

/** 
* Get name 
* 
* @return string $name 
*/ 
public function getName() 
{ 
    return $this->name; 
} 

/** 
* Set translations 
* 
* @param ArrayCollection $translations 
* @return Product 
*/ 
public function setTranslations($translations) 
{ 
    foreach ($translations as $translation) { 
     $translation->setObject($this); 
    } 

    $this->translations = $translations; 
    return $this; 
} 

/** 
* Get translations 
* 
* @return ArrayCollection 
*/ 
public function getTranslations() 
{ 
    return $this->translations; 
} 

這是我ProductTranslation:

class ProductTranslation extends AbstractPersonalTranslation 
{ 
/** 
* @MongoDB\ReferenceOne(targetDocument="MyBundle\ProductBundle\Document\Product", inversedBy="translations") 
* 
*/ 
public $object; 

} 

我仍然收到這個「所需的選項 」類「 丟失」。錯誤,我不知道是什麼問題。

+0

有同樣的問題,任何更新? –

回答

0

您收到此錯誤是因爲MongoDB ODM映射在Reference上創建了一個字段映射。

例如,當您有ManyToOne或OneToMany關係時,ORM不會創建字段映射。

因此,a2lix將您的object字段視爲通常的映射字段。由於表單生成器會解決此類object字段,例如document類型,因此您需要提供class選項才能使其正常工作。

但是,如果你想提供這個選項,那麼你的object字段將被渲染爲可翻譯的字段,它肯定會吸引。

所以,請試試這個:

->add('translations', 'a2lix_translations', [ 
    'exclude_fields' => [ 
     'object', 
    ] 
]) 

它會幫助你與這個特殊的問題。