2012-12-18 73 views
0

我正在构建一个CRM系统,我遇到了一个我无法解决的奇怪问题。当我尝试创建一个新的CustomerCase实体,我想分配CaseState实体,所以这是我在CustomerCaseController.php的createAction做:Symfony2传递参数为空

$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方法时,它只会变为空。如果我做$ entity-> setCaseState($ customerStateObject-> getId()),我得到相同的错误信息,但是这次null更改为整数。

CustomerCase与CaseState具有manyToOne关系。

这很好,如果我使用formBuilder的add()方法并跳过所有这些手动工作,但由于我使用了一个非常具体的自动填充jQuery下拉框从嵌套树结构中选择CaseState,手动添加下拉菜单并使用$ request-> request-> get()读取它。

我已经与这部分战斗了近三天了,并将不胜感激每一次我可以得到的帮助!

+0

'$ caseStateId'是否有适当的值?你尝试将它转换为(int)吗? – topaz1008

回答

3

最后我得到它的工作!原因是$请求缺少一些参数,因为树枝模板缺少form_rest(表单)。增加后,一切都开始奏效。谢谢!