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

  • Home
  • SEARCH
  • 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 9136281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:55:56+00:00 2026-06-17T08:55:56+00:00

I have an entity field type in my form, but then when I try

  • 0

I have an entity field type in my form, but then when I try to get the values from the controller I get an error.

This is my form builder

$builder
        ->add('recursos', 'entity', array(
                'class' => 'SIGIConvocatoriasBundle:Recurso',
                'property' => 'nombre',
                'multiple' => true,
                'mapped' => false
                ))
        ->add('requisitos', 'entity', array(
                'class' => 'SIGIConvocatoriasBundle:Requisito',
                'property' => 'nombre',
                'multiple' => true,
                'mapped' => false
                ))
    ;

and this is my controller

$entity  = new Convocatoria();
$form = $this->createForm(new ConvocatoriaType(), $entity);
$form->bind($request);
$recursos = $request->request->get('recursos');
foreach ($recursos as $recurso)
{
    //Do something ...
}

But I get an error here

Invalid argument in foreach ...

Like if the $recursos variable is empty or something, and I get a 'recursos' => null in the symfony exception.
I’d really appreciate some help here 😀

  • 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-17T08:55:57+00:00Added an answer on June 17, 2026 at 8:55 am

    The request itself contains raw data (scalars).
    When you bind the request to the form, it will transform this raw data to normalized data.
    The array of ids will be transformed to an array of entities, and then be passed to $entity->setRecursos(); // or each one to $entity->addRecurso();

    $form = $this->createForm(new ConvocatoriaType(), $entity)
    $form->bind($request);
    
    $formData = $request->request->get($form->getName());
    $formData['recursos']; // should be an array of ids
    
    $entity->getRecursos(); // array of entities
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an entity type form field in my Symfony2 project. $builder = $this->createFormBuilder();
I have a field aliases of type java.util.Set in one Entity . This Set
I use entity for form field type, and get my list of options for
In my form I have field of type entity . How to disable validation
I have an Entity with the field url , this entity is being persisted
I have a form using this class type: class DespesasContainerType extends AbstractType { public
I have a form with a collection type field, rendered like that: <div id=beneficiosTab
I have a form type which has a field that is not in the
I'm using the entity Field Type in a Symfony2.1 form. Here, I'm going to
I have the following situation: a form field type date a validation pattern like

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.