Symfony2:update中断了映射的错误验证

时间:2013-10-13 14:06:58

标签: php validation symfony

在使用2.3.4时,我构建了一个带有未映射字段的表单。表单按预期运行。未对未映射的字段应用验证。在今天更新到2.3.6之后(来自使用stable和dev版本的实验),未映射的字段会生成验证错误

  

isHead:错误:此值无效。

$form->getErrorsAsString()

中的

编辑3:用例

一个家庭由一系列成员组成。创建家庭时,必须至少有一名成员,并被指定为户主。有时需要将不同的成员指定为户主。非映射字段isHead在编辑表单中构造,其值为成员的id。将此值与家庭实体的head_of_house_id进行比较,以确定是否必须保留新的户主。

编辑 - 添加表单字段;编辑2显示添加的约束

    ->add('isHead', 'choice', array(
        'expanded' => true,
        'mapped' => false,
        'constraints' => array(new NotBlank(array('message' => 'This is a bogus value')))
    ))

composer.json:“minimum-stability”:“stable”,:

"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "2.3.*",
    "doctrine/orm": ">=2.2.3,<2.4-dev",
    "doctrine/doctrine-bundle": "1.2.*",
    "twig/extensions": "1.0.*",
    "symfony/assetic-bundle": "2.3.*",
    "symfony/swiftmailer-bundle": "2.3.*",
    "symfony/monolog-bundle": "2.3.*",
    "sensio/distribution-bundle": "2.3.*",
    "sensio/framework-extra-bundle": "2.3.*",
    "sensio/generator-bundle": "2.3.*",
    "incenteev/composer-parameter-handler": "~2.0",
    "jms/security-extra-bundle": "dev-master",
    "beberlei/DoctrineExtensions": "*",
    "knplabs/knp-menu":"2.0.*@dev",
    "knplabs/knp-menu-bundle":"dev-master",
    "psliwa/pdf-bundle": "dev-master"
},

作曲家更新输出

Updating dependencies (including require-dev)
  - Updating twig/twig (dev-master 09c386b => v1.14.0)
    Checking out 224fc55635d544a2ec8edb3592be18db5a093f59

  - Updating doctrine/lexer (dev-master bc0e1f0 => v1.0)
    Checking out 2f708a85bb3aab5d99dab8be435abd73e0b18acb

  - Updating doctrine/inflector (dev-master 8b4b3cc => v1.0)
    Checking out 54b8333d2a5682afdc690060c1cf384ba9f47f08

  - Updating doctrine/collections (dev-master bcb5377 => v1.1)
    Checking out 560f29c39cfcfbcd210e5d549d993a39d898b04b

  - Updating doctrine/common (2.4.x-dev c94d6ff => v2.4.1)
    Checking out ceb18cf9b0230f3ea208b6238130fd415abda0a7

  - Updating symfony/symfony (v2.3.4 => v2.3.6)
    Checking out d0597156c4c03ceca039f6b7770a47397ba295f0

  - Updating symfony/icu (1.2.x-dev 98e197d => v1.2.0)
    Checking out 7299cd3d8d6602103d1ebff5d0a9917b7bc6de72

  - Updating incenteev/composer-parameter-handler (dev-master bc06242 => v2.0
    Checking out 2310d74a751025f02221e0faf69d31440df71b73

  - Updating doctrine/dbal (2.3.x-dev 59c310b => 2.3.4)
    Checking out 2a37b007dda8e21bdbb8fa445be8fa0064199e13

  - Updating doctrine/orm (2.3.x-dev 66d8b43 => 2.3.4)
    Checking out a41b02c080114c0de3da4ee9fba61f7d18fae7d0

  - Updating beberlei/doctrineextensions (dev-master bed4645 => v0.1)
    Checking out d38b081dbf826960bd9aad9d7dabed5164d3e7d3

  - Updating kriswallsmith/assetic (1.1.x-dev 1d671c5 => v1.1.2)
    Checking out 735cffd3982c6e8cdebe292d5db39d077f65890f

  - Updating symfony/assetic-bundle (2.3.x-dev 65bd076 => v2.3.0)
    Checking out 146dd3cb46b302bd471560471c6aaa930483dac1

  - Updating jms/metadata (dev-master 246d709 => 1.4.2)
    Checking out 246d7096801ce29b5aea30a1abf0277ccfb9f055

  - Updating jms/cg (dev-master 0d8d8c7 => 1.0.0)
    Checking out ce8ef43dd6bfe6ce54e5e9844ab71be2343bf2fc

  - Updating jms/aop-bundle (dev-master 93f41ab => 1.0.0)
    Checking out 8ef7db0043188f58da18f931937008f95b308921

  - Updating jms/di-extra-bundle (dev-master 01029f6 => 1.4.0)
    Checking out 7fffdb6c96fb922a131af06d773e1e6c5301d070

  - Updating phpoption/phpoption (dev-master 1c7e801 => 1.3.0)
    Checking out 1c7e8016289d17d83ced49c56d0f266fd0568941

  - Updating jms/parser-lib (dev-master d5961fa => 1.0.0)
    Checking out c509473bc1b4866415627af0e1c6cc8ac97fa51d

  - Updating zendframework/zend-memory (dev-master 7005247 => 2.2.4)
    Checking out 700524702bc3b6142107eac9c71f1b56236b3cd0

  - Updating zendframework/zend-stdlib (dev-master d8013ca => 2.2.4)
    Checking out 7c87ce4e840957596bf3401fa4ae4fb0355682e2

  - Updating zendframework/zend-eventmanager (dev-master f325fee => 2.2.4)
    Checking out f325feef4e1a19b873936e5b116980fbe88dd176

  - Updating zendframework/zend-servicemanager (dev-master e05c29f => 2.2.4)
    Checking out e05c29f8d7da6e2c26d2d8b334324932a73afa78

  - Updating zendframework/zend-cache (dev-master fa5343b => 2.2.4)
    Checking out 64044faa106710a6dd2735a06b5034cd9cb2dc67

  - Updating zendframework/zendpdf (dev-master 6efcb51 => 2.0.2)
    Checking out 041f90c339cff63a3c4d03a28ef1ea5188059793

  - Updating psliwa/php-pdf (dev-master 51d9be9 => 1.2.1)
    Checking out 2ab60bd35f5095826ef28df56c8c3a08031201fe

  - Updating jdorn/sql-formatter (dev-master 51a660e => v1.2.9)
    Checking out bd1f09133f6dbbe0713856910e58ea9480c2be58

  - Updating monolog/monolog (dev-master 8e5a671 => 1.6.0)
    Checking out f72392d0e6eb855118f5a84e89ac2d257c704abd

  - Installing knplabs/knp-menu-bundle (dev-master 1b07578)
    Cloning 1b07578738d3425c09cfbd153276382388994f46

1 个答案:

答案 0 :(得分:0)

这可能是因为Symfony团队修复了choice类型和expanded选项的错误。

  

9542d72: [Form] Fixed expanded choice field to be marked invalid when unknown choices are submitted

这是在Symfony 2.3.5 中合并并发布的。

由于您未指定choices选项,因此您指定的值不是有效选项,因此会正确失败。

从我在字段名称中看到的内容,您需要一个checkbox类型字段。