Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
传递的Symfony2参数为空_Symfony_Null_Arguments - Fatal编程技术网

传递的Symfony2参数为空

传递的Symfony2参数为空,symfony,null,arguments,Symfony,Null,Arguments,我正在建立一个CRM系统,我遇到了一个我无法解决的奇怪问题。当我尝试创建一个新的CustomerCase实体时,我想为它分配一个CaseState实体,因此这是我在CustomerCaseController.php的createAction中所做的: $caseStateId = $request->request->get('caseState_id'); $caseState = $this->getDoctrine()->getManager()-

我正在建立一个CRM系统,我遇到了一个我无法解决的奇怪问题。当我尝试创建一个新的CustomerCase实体时,我想为它分配一个CaseState实体,因此这是我在CustomerCaseController.php的createAction中所做的:

    $caseStateId = $request->request->get('caseState_id');
    $caseState = $this->getDoctrine()->getManager()->getRepository('HSWAshaBundle:CaseState')->findOneById($caseStateId);
    $entity  = new CustomerCase();
    $entity->setCaseState($caseState);
...... etc.....
在使用setCaseState方法之前,一切正常。运行setCaseState后,我得到以下错误:

Catchable Fatal Error: Argument 1 passed to HSW\AshaBundle\Entity\CustomerCase::setCaseState() must be an instance of HSW\AshaBundle\Entity\CaseState, null given, called in /home/webuser/Symfony/vendor/symfony/symfony/src/Symfony/Component/Form/Util/PropertyPath.php on line 538 and defined in /home/webuser/Symfony/src/HSW/AshaBundle/Entity/CustomerCase.php line 843
奇怪的是$caseState实际上是一个caseState对象(因为例如$caseState->getName()可以工作并为所选caseState提供正确的名称)出于某些令人兴奋的原因,当我使用setCaseState方法时,它只会变为null。如果执行$entity->setCaseState($customerStateObject->getId()),则会收到相同的错误消息,但这次null将更改为整数

CustomerCase与CaseState有多个关系

如果我使用formBuilder的add()方法并跳过所有这些手动工作,这就很好了,但是因为我使用了一个非常特定的自动填充jQuery下拉列表来从嵌套树结构中选择CaseState,所以我必须手动添加下拉列表并使用$request->request->get()读取它


我已经为这个部件奋斗了将近三天了,非常感谢我在这方面所能得到的一切帮助

我终于成功了!原因是$request缺少一些参数,因为细枝模板缺少form_rest(form)。加上这些之后,一切都开始起作用了。谢谢大家!

我终于成功了!原因是$request缺少一些参数,因为细枝模板缺少form_rest(form)。加上这些之后,一切都开始起作用了。谢谢大家!

$caseStateId
是否具有正确的值?您是否尝试将其强制转换为(int)?
$caseStateId
是否具有正确的值?你试过把它转换成(int)吗?