简体   繁体   English

Symfony2数组到字符串的转换

[英]Symfony2 Array to string conversion

i'm working on symfony2 project and i get this exception. 我正在symfony2项目上工作,但出现此异常。 anybody have an idea on what is causing it ? 有人知道是什么原因造成的吗?

Notice: Array to string conversion in C:\\wamp\\www\\EmploiPublic\\vendor\\symfony\\symfony\\src\\Symfony\\Component\\Form\\Extension\\Core\\ChoiceList\\ChoiceList.php line 457 注意:C:\\ wamp \\ www \\ EmploiPublic \\ vendor \\ symfony \\ symfony \\ src \\ Symfony \\ Component \\ Form \\ Extension \\ Core \\ ChoiceList \\ ChoiceList.php行中的数组到字符串的转换

protected function fixIndex($index)
{
    if (is_bool($index) || (string) (int) $index === (string) $index) { //this is line 457
        return (int) $index;
    }

    return (string) $index;
}

the error is generated after calling the $form->bind($request) method; 在调用$ form-> bind($ request)方法后生成错误;

   if ($request->isMethod('POST')) {

        $form->bind($request);
        $searchQuery = $form->getData();
    }

When bind() tries to map your data values to the form, it's getting an array value for a Choice field where it's expecting a single string value. 当bind()尝试将您的数据值映射到表单时,它将获得一个Choice字段的数组值,该字段期望一个字符串值。

It may be that the Choice field should allow multi-select, in which case you need to make sure that when you create the Choice control you set ' multiple ' to true (and also consider the ' expanded ' option). 可能是Choice字段应允许多选,在这种情况下,您需要确保在创建Choice控件时将' multiple '设置为true(并考虑使用' expanded '选项)。

Otherwise, it's not possible to diagnose your issue unless you post the code that creates the form and the class or data structure that maps onto the form. 否则,除非您发布创建表单的代码以及映射到表单的类或数据结构,否则无法诊断问题。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM