0

I'm building a CRM system and I faced a weird problem I'm unable to solve. When I try to create a new CustomerCase entity, I want to assign a CaseState entity for it, so this is what I do in the createAction of CustomerCaseController.php:

    $caseStateId = $request->request->get('caseState_id');
    $caseState = $this->getDoctrine()->getManager()->getRepository('HSWAshaBundle:CaseState')->findOneById($caseStateId);
    $entity  = new CustomerCase();
    $entity->setCaseState($caseState);
...... etc.....

Everything works just fine until the setCaseState method. After running setCaseState, I get the following error:

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

The weird part is that $caseState really is a CaseState object (because for example $caseState->getName() works and gives me the correct name for the selected CaseState). For some mind blowing reason it just turns null when I use the setCaseState method. If I do $entity->setCaseState($customerStateObject->getId()), I get the same error message, but this time null changes to integer.

The CustomerCase has a manyToOne relationship with CaseState.

This works just fine if I use the formBuilder's add() method and skip all this manual work, but since I'm using a very specific auto-populating jQuery dropdown for selecting the CaseState from a nested tree structure, I had to manually add the dropdown and read it with $request->request->get().

I've been fighting with this part for almost three days now and would greatly appreciate every help I can get with this!

1
  • Does $caseStateId have the proper value ? did you try casting it to (int) ? Commented Dec 18, 2012 at 19:19

1 Answer 1

3

Finally I got it to work! The reason was $request was missing some parameters because the twig template was missing form_rest(form). After adding that, everything started to work. Thank you!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.