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 8069109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:54:49+00:00 2026-06-05T12:54:49+00:00

I have a problem when submitting a from with a related entity. I get

  • 0

I have a problem when submitting a from with a related entity. I get the following error message when submitting the form:

Catchable Fatal Error: Argument 1 passed to 
My\ReportBundle\Entity\Clearance::setProjectProject() must be an instance of 
My\ReportBundle\Entity\Project, null given, called in
/var/www/Symfony/src/My/ReportBundle/Controller/DefaultController.php on line 85 and 
defined in /var/www/Symfony/src/My/ReportBundle/Entity/Clearance.php line 272

The form builder code looks like this:

namespace My\ReportBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class ClearanceType extends AbstractType
{


public function buildForm(FormBuilder $builder, array $options)
{
    $builder
        // Fields from the clearance entity removed ...
        // here is the problematic entry
        ->add('projectProject','entity',
         array('class'=>'My\ReportBundle\Entity\Project', 'property'=>'projectId'))
      ;
     }

      public function getName()
     {
         return 'my_reportbundle_clearancetype';
      }

And the controller contains this code:

     public function newclearanceAction()
     {
    $request = $this->getRequest();
    $id = $request->query->get('projectId');
    $em = $this->getDoctrine()->getEntityManager();
    $project = $em->getRepository("MyReportBundle:Project")->find($id);

    $clearance = new Clearance();
    $clearance->setProjectProject($project);
    $form = $this->createForm(new ClearanceType(), $clearance);

    if ($request->getMethod() == 'POST'){
            $form->bindRequest($request);

            if($form->isValid()) {
                    $em = $this->getDoctrine()->getEntityManager();
                    $em->persist($clearance);
                    $em->flush();
                    return $this->
                    redirect($this->generateUrl('MyReportBundle_project_list'));
            }
         }
         return $this->render('MyReportBundle:Clearance:new.html.twig',
                 array('form'=>$form->createView()));

I don’t have any idea how to fix this.
Thanks for any help!

  • 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-05T12:54:50+00:00Added an answer on June 5, 2026 at 12:54 pm

    when you post the form are you setting projectId in the query string?

    If not try:

    $request = $this->getRequest();
    
    $em = $this->getDoctrine()->getEntityManager();
    $clearance = new Clearance();
    
    if($request->getMethod() != 'POST'){
        $id = $request->query->get('projectId'); 
        $project = $em->getRepository("MyReportBundle:Project")->find($id);
        $clearance->setProjectProject($project);
    }
    $form = $this->createForm(new ClearanceType(), $clearance);
    

    The error is coming because you are not getting a project when you try and find one by id, thus when you try and set the project you are passing a null value through.

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

Sidebar

Related Questions

I have the following error message in when submitting from my perforce client (p4v):
I have very strange problem while I am submitting a practice problem on codechef.
I have problem with show or hide form in Window Form Application. I start
I have problem with UIWebView delay when the load image from url. In my
I have problem SIMILAR to preventing form data reposting, but not quite the same
I want to interrupt and prevent a form from submitting using jQuery. Here's my
I have the following problem in application express which is driving me crazy: I
I am submitting from a form to another php page which is supposed to
I have 2 <h:form> elements following each other (not one within the other) such
I have a problem with my mysql insert statement. I have a form which

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.