简体   繁体   English

升级到2.8后,Symfony property_path无法正常工作

[英]Symfony property_path not working properly after upgrade to 2.8

I'm making migration from Symfony 2.7 to 2.8. 我正在从Symfony 2.7迁移到2.8。

My model has field $text that is array and has a setter: 我的模型有字段$ text,它是数组并且有一个setter:

public function setText(array $text)
{
    $this->$text = $text;

    return $this;
}

Text that i'm trying to save has two fields for different languages (FormType part bellow): 我正在尝试保存的文本有两个不同语言的字段(FormType part bellow):

$builder->add('text_en', 'text', array(
    'required' => false,
    'property_path' => 'text[en]'
));
$builder->add('text_pl', 'text', array(
    'required' => false,
    'property_path' => 'text[pl]'
));

On Symfony 2.7 everything is ok (setter is firing once with values from both fields), but after upgrade to 2.8, setter is firing two times for each field, and result is that $text has only value from second field instead of both (second time it overrides value from field with 'en' language). 在Symfony 2.7上一切正常(setter使用两个字段的值触发一次),但升级到2.8后,setter为每个字段触发两次,结果是$ text只有第二个字段而不是两个字段的值(第二个)时间它用“en”语言覆盖字段的值。 Any suggestions? 有什么建议么?

You can do it like this (in case that you revert back to older Symfony version :)): 你可以这样做(如果你恢复到旧的Symfony版本:)):

public function setText(array $text)
{
    foreach ($text as $key => $value) {
    $this->$text[$key] = $value;
    }

    return $this;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Symfony 3.4升级后(从2.8开始)未设置特征值 - Trait value not being set after Symfony 3.4 upgrade (from 2.8) 将 php 从 5.6 升级到 7.4 后,项目 symfony 2.8 中的 AppKernel.php 出现问题 - Problem with AppKernel.php in project symfony 2.8 after upgrade php from 5.6 to 7.4 symfony 2.8 @ORM \\ PrePersist无法正常工作 - symfony 2.8 @ORM\PrePersist is not working 使用 Symfony 升级 2.8-> 3.4 进行学说迁移时出错 - Error while Doctrine Migration with Symfony upgrade 2.8-> 3.4 symfony2.8 @ORM \\ HasLifecycleCallbacks()无法正常工作 - symfony2.8 @ORM\HasLifecycleCallbacks() is not working Symfony 2.8 Form Builder无法正常工作 - Symfony 2.8 Form Builder isn't working 这两个命令都不能在 symfony 2.8 中的应用程序/控制台上运行 - Neither command is working at app/console in symfony 2.8 集合内的Symfony 2.8表单子集合未正确显示 - Symfony 2.8 forms sub collections inside collections not displayed properly “保留的指示符”@“不能启动纯标量”——在 YML 文件中。 (升级 SYMFONY 2.8 到 SYMFONY 3.0) - “The reserved indicator ”@“ cannot start a plain scalar” — in YML file. (UPGRADE SYMFONY 2.8 TO SYMFONY 3.0) Symfony 2.8:从2.7.7更新到2.8.0后isScopeActive弃用 - Symfony 2.8: isScopeActive deprecation after update to 2.8.0 from 2.7.7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM