Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:29:38+00:00 2026-06-12T02:29:38+00:00

I am building this form in symfony 2.0 and for some reason when I

  • 0

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:

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

My code:

public function popupChildAction($parentid)
{
    $entity  = new Page();
    $entity->setWebsite($this->getWebsite());

    $parent = $this->getDoctrine()
    ->getRepository('MelvinLoosCMSCoreBundle:Page')
    ->findOneById($parentid);

    if (!$parent)
    {
        throw $this->createNotFoundException('No parent found with given id: "' . $parentid . '"');
    }
    $entity->setParent($parent);

    $entity->setCreatedBy($this->getUser());
    //$entity->setPageType();
    $form   = $this->createForm(new PageChildType(), $entity);
    $request = $this->getRequest();
    $form->bindRequest($request);

    if ($form->isValid()) {

        $em = $this->getDoctrine()->getEntityManager();
        $em->persist($entity);
        $em->flush();

        return $this->redirect($this->generateUrl('page_show', array('id' => $entity->getId())));

    }

    return $this->render('MelvinLoosCMSCoreBundle:Page:new_popup.html.twig', array(
            'entity' => $entity,
            'form'   => $form->createView(),
            'parent' => $parent
    ));
}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:29:39+00:00Added an answer on June 12, 2026 at 2:29 am

    Totally forgot that I had this question still floating around… Anyway I got around my problem, still don’t know why I got the error but I solved it with quite a easy solution.

    Instead of setting the parent for the child, I did the reverse and set the child for the parent. My code is the following (There is also new code in there that’s irrelevant because I fixed it some time ago).

    public function popupChildAction($parentid)
    {
        $parent = $this->getDoctrine()
        ->getRepository('MelvinLoosCMSCoreBundle:Page')
        ->findOneById($parentid);
    
        if (!$parent)
        {
            throw $this->createNotFoundException('No parent found with given id: "' . $parentid . '"');
        }
        $entity  = new Page();
        $entity->setWebsite($this->getWebsite());
        $entity->setCreatedBy($this->getUser());
        $form   = $this->createForm(new PageChildType(), $entity);
        $request = $this->getRequest();
        $form->bindRequest($request);
    
        if ($form->isValid()) {
            $em = $this->getDoctrine()->getEntityManager();
            $parent->setChildren($entity);
            $em->persist($entity);
            $em->flush();
    
            return $this->redirect($this->generateUrl('page_show', array('id' => $entity->getId())));
    
        }
    
        return $this->render('MelvinLoosCMSCoreBundle:Page:new_popup.html.twig', array(
                'entity' => $entity,
                'form'   => $form->createView(),
                'parent' => $parent
        ));
    }
    

    Like I said there is newer code that is irrelevant but what it’s all about is the part with
    $parent->setChildren($entity); and now it works… hope this helps someone!
    Thanks for everyone that gave input!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing a JSON response via $.ajax() and building a form from this object's
I am building a mobile website, In this a form is there but no
I have a simple form on an ASP.NET MVC site that I'm building. This
I'm looking to get some advice; I'm about to build an OOP signup form
I'm building my first form with django, and I'm seeing some behavior that I
I've been building this site that will get run an API depending on the
Anyone able to offer some ideas on this? Basically the module I'm building has
I'm building a simple form mailer in symfony using sfExtraForm plugin captcha. Everything works
I am building this C# windows application. On a certain Form, I am using
I'm building this application using PHP, MySQL and jQuery. Essentially it's a checklist management

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.