Note that there are some explanatory texts on larger screens.

plurals
  1. POVar filled with object suddenly null, what happened?
    text
    copied!<p>Ok I usually don't ask for help but it's driving me crazy and I have to finish this project so bare with me here. Let me know if I left out any info that might help.</p> <p>So I am building this form in symfony 2.0 and for some reason when I retrieve a object from the db and put it into an object it is gone when I want to save it so I get the following error: </p> <pre><code>Catchable Fatal Error: Argument 1 passed to MelvinLoos\CMS\CoreBundle\Entity\Page::setParent() must be an instance of MelvinLoos\CMS\CoreBundle\Entity\Page, null given, called in vendor\symfony\src\Symfony\Component\Form\Util\PropertyPath.php on line 347 and defined in src\MelvinLoos\CMS\CoreBundle\Entity\Page.php line 233 </code></pre> <p>My code: </p> <pre><code>public function popupChildAction($parentid) { $entity = new Page(); $entity-&gt;setWebsite($this-&gt;getWebsite()); $parent = $this-&gt;getDoctrine() -&gt;getRepository('MelvinLoosCMSCoreBundle:Page') -&gt;findOneById($parentid); if (!$parent) { throw $this-&gt;createNotFoundException('No parent found with given id: "' . $parentid . '"'); } $entity-&gt;setParent($parent); $entity-&gt;setCreatedBy($this-&gt;getUser()); //$entity-&gt;setPageType(); $form = $this-&gt;createForm(new PageChildType(), $entity); $request = $this-&gt;getRequest(); $form-&gt;bindRequest($request); if ($form-&gt;isValid()) { $em = $this-&gt;getDoctrine()-&gt;getEntityManager(); $em-&gt;persist($entity); $em-&gt;flush(); return $this-&gt;redirect($this-&gt;generateUrl('page_show', array('id' =&gt; $entity-&gt;getId()))); } return $this-&gt;render('MelvinLoosCMSCoreBundle:Page:new_popup.html.twig', array( 'entity' =&gt; $entity, 'form' =&gt; $form-&gt;createView(), 'parent' =&gt; $parent )); } </code></pre> <p>As you can see I put in a if statement to check if $parent is filled and I also tried a var_dump to double check, it is defiantly filled with an object. But for some reason when I call the setParent() function of the entity object it fills it with null.... Maybe I am just overlooking something because I have been working too long but all help is greatly appreciated. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload