【问题标题】:ContextErrorException when submit form with A2lix使用 A2lix 提交表单时出现 ContextErrorException
【发布时间】:2014-02-13 16:57:59
【问题描述】:

对于多语言表单,我使用 Gedmo Translatable 和 A2lix 并使用 personal translations,因此对于 1 个实体,我有 1 个翻译:Categ 和 CategTranslation。

显示表单一切正常,但当我提交时出现此错误:

ContextErrorException:警告:缺少 Immo\AnnonceBundle\Entity\CritereCategTranslation::__construct() 的参数 1,在 /var/www/kimsufi/asimmobilier/vendor/a2lix/translation-form-b​​undle/A2lix/TranslationFormBundle/Form 中调用/DataMapper/GedmoTranslationMapper.php 在第 70 行并在 /var/www/kimsufi/asimmobilier/src/Immo/AnnonceBundle/Entity/CritereCategTranslation.php 第 29 行中定义

这是我的类别类型:

->add('translations', 'a2lix_translations_gedmo', array(
                    'translatable_class' => 'Immo\AnnonceBundle\Entity\CritereCateg',
                    'locales' => array('fr', 'en'),
                    'required' => false,
                    'fields' => array(
                        'libelle' => array(
                            'field_type' => 'text',
                            'locale_options' => array(
                                'en' => array(
                                    'label' => 'Libellé du critère (en) :',
                                    'attr' => array('placeholder' => 'Example : Convenience, proximity, etc.')
                                ),
                                'fr' => array(
                                    'label' => 'Libellé du critère (fr) :',
                                    'attr' => array('placeholder' => 'Exemple : A proximité, commodités, etc.')
                                )
                            )
                        )
                    )
                )
             );

我的 CritereCategTranslation :

use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation;
/**
 * @ORM\Entity
 * @ORM\Table(name="criterecateg_translations",
 *     uniqueConstraints={@ORM\UniqueConstraint(name="lookup_unique_idx", columns={
 *         "locale", "object_id", "field"
 *     })}
 * )
 */
class CritereCategTranslation extends AbstractPersonalTranslation
{

    /**
     * Convenient constructor
     *
     * @param string $locale
     * @param string $field
     * @param string $value
     */
    public function __construct($locale, $field, $value)
    {
        $this->setLocale($locale);
        $this->setField($field);
        $this->setContent($value);
    }

    /**
     * @ORM\ManyToOne(targetEntity="CritereCateg", inversedBy="translations")
     * @ORM\JoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE")
     */
    protected $object;


}

有什么想法吗?谢谢

【问题讨论】:

    标签: forms symfony doctrine translation stofdoctrineextensions


    【解决方案1】:

    移除 _construct 方法。你不需要它。

    【讨论】:

    • 谢谢,我在你回答之前找到了这个,但是谢谢。 :)
    猜你喜欢
    • 2015-09-16
    • 2018-10-22
    • 2021-06-15
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 2017-03-28
    • 2015-10-30
    • 1970-01-01
    相关资源
    最近更新 更多