2015-06-22 40 views
1

我用未定義指數:translationClass在GedmoTranslationForm

composer.json

"symfony/symfony": "2.6.*", 
"doctrine/orm": "~2.2,>=2.2.3,<2.5", 
"doctrine/dbal": "<2.5", 
"doctrine/doctrine-bundle": "~1.2", 
"stof/doctrine-extensions-bundle": "[email protected]", 
"a2lix/translation-form-bundle": "1.*@dev", 

config.yml

stof_doctrine_extensions: 
    default_locale: en 
    orm: 
     default: 
      translatable: true 
      sluggable: true 
      sluggable: true 
      timestampable: true 

a2lix_translation_form: 
    #locale_provider: default  # [1] 
    default_required: false 
    locales: [de, pl,en]   # [1-a] 
    manager_registry: doctrine  # [2] 
    templating: "A2lixTranslationFormBundle::default.html.twig"  # [3] 

實體

use Doctrine\Common\Collections\ArrayCollection; 
use Doctrine\ORM\Mapping as ORM; 
use APY\DataGridBundle\Grid\Mapping as GRID; 
use Gedmo\Mapping\Annotation as Gedmo; 
use Symfony\Component\Validator\Constraints as Assert; 

/** 
* @ORM\Entity 
* @ORM\Table(name="c_Coupon") 
* @Gedmo\TranslationEntity(class="CouponTranslation") 
*/ 
class Coupon { 

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

    /** 
    * @ORM\Column(length=8, unique=true) 
    */ 

    private $name; 

    /** 
    * @ORM\Column(type="text", nullable=true) 
    * @Gedmo\Translatable 
    * @var string 
    */ 
    private $description; 



    /** 
    * @GRID\Column(title="translations") 
    * @ORM\OneToMany(
    *  targetEntity="CouponTranslation", 
    * mappedBy="object", 
    * cascade={"persist", "remove"} 
    *) 
    * @Assert\Valid(deep = true) 
    */ 
    private $translations; 

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

    public function addTranslation(CountryTranslation $t) 
    { 
     if (!$this->translations->contains($t)) { 
      $this->translations[] = $t; 
      $t->setObject($this); 
     } 
    } 


    /** 
    * Set translations 
    * @param ArrayCollection $translations 
    * @return $this 
    */ 
    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; 
    } 

CouponTranslation

<?php 
namespace Mea\CharterBundle\Entity; 
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation; 
use Doctrine\ORM\Mapping as ORM; 
/** 

* @ORM\Entity 
* @ORM\Table(name="c_coupon_translations", 
* uniqueConstraints={@ORM\UniqueConstraint(name="lookup_unique_idx", columns={ 
*  "locale", "object_id", "field" 
* })} 
*) 
*/ 
class CouponTranslation extends AbstractPersonalTranslation{ 
    /** 
    * @ORM\ManyToOne(targetEntity="Coupon", inversedBy="translations") 
    * @ORM\JoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE") 
    */ 
    protected $object; 

    public function __construct($locale='', $field='', $value='') 
    { 
     if($locale)$this->setLocale($locale); 
     if($field)$this->setField($field); 
     if($value)$this->setContent($value); 
    } 

} 

形式建立

$builder 
      //->add('name') 
      ->add('translations', 'a2lix_translations_gedmo', array(
        'translatable_class' => "Mea\\CharterBundle\\Entity\\CouponTranslation", 
        'fields'=>array(
         'name'=>array(), 
         'description'=>array(
          'field_type' => 'ckeditor' 
         ) 
        ) 
       ) 
      ); 

,並得到錯誤注意:未定義指數:translationClass 在供應商/ a2lix /翻譯形式的束/ A2lix/TranslationFormBundle/TranslationForm/GedmoTranslationForm.php在第57行

+0

嗨。你解決了這個問題嗎? – y2josei

回答

-1

您正在調用某個數組,其中沒有定義關鍵字'translationClass'。 (最近我看到它是在這裏:

'translatable_class' => "Mea\\CharterBundle\\Entity\\CouponTranslation", 

,但我不知道)

這個線程可以幫助你:

Reference - What does this error mean in PHP?