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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:22:30+00:00 2026-06-03T02:22:30+00:00

I am using Form Classes to build the various form in my project. In

  • 0

I am using Form Classes to build the various form in my project.

In the Entity Type file, for the buildForm function, there is a secondary parameter of “array $options” (this is shown in the official Symfony 2 Documentation, but never mentioned, ever!)

I have fed an array into the createForm function in my controller but now I am totally stumped on how to retrieve the stored values?

$form = $this->createForm(new ProductType(array(), array('id' => '2')), $product);

The only thing I have found about getting the options is using the getOption() function, but that doesn’t exist in Symfony 2 (the post I found was from 2010).

I tried using:

$id = $options['id'];

But when I try to use $id anywhere, I get the error:

Notice: Undefined index: id

What gives?

How do I retrieve my values from the $options array? Am I even setting them correctly in the first place?

EDIT – More code:

Form Class

<?php

namespace DEMO\DemoBundle\Form\Product;

use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class ProductType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('name')
            ->add('slug')
            ->add('reference')
            ->add('description')
            ->add('active_from')
            ->add('active_till')
            ->add('is_active')
            ->add('category', 'entity', array(
                'class' => 'DEMO\DemoBundle\Entity\Product\ProductCategory',
                'query_builder' => function(EntityRepository $er) {
                    return $er->createQueryBuilder('u')
                        ->where('u.section = :id')
                        ->setParameter('id', ***ID VARIABLE NEEDS TO GO HERE***)
                        ->orderBy('u.root', 'ASC')
                        ->addOrderBy('u.lft', 'ASC');
                },
                'empty_value' => 'Choose an option',
                'property' => 'indentedName',
            ));
    }

    public function getDefaultOptions()
    {
        return array(
            'data_class' => 'DEMO\DemoBundle\Entity\Product\Product'
        );
    }

    public function getName()
    {
        return 'demo_demobundle_product_type';
    }
}
  • 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-03T02:22:31+00:00Added an answer on June 3, 2026 at 2:22 am

    Well, it turns out, Gregoires answer was very close, but gave me and “Undefined variable” error when trying to actually but the variable into the createQueryBuilder function.

    I spent a while trying to figure out why and found the issue. You have to add an extra parameter to the function in the “query_builder” option, like such:

    'query_builder' => function(EntityRepository $er) use ($options) {
                        return $er->createQueryBuilder('u')
                            ->where('u.section = :id')
                            ->setParameter('id', $options['id'])
                            ->orderBy('u.root', 'ASC')
                            ->addOrderBy('u.lft', 'ASC');
                    },
    

    The magic setting being “use ($options)”. This allows you to successfully use $options[‘id’] in the Query Builder.

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

Sidebar

Related Questions

I'm using the Entity Framework version 4.2. There are two classes in my small
I've been using the following code in my Web form code-behind classes. I want
I'm using a form with 2 classes ( ArticleType and ArticleHandler ) for my
I am building a form using HTML5 form validation. I have the CSS classes
I just started using Twig and I'm trying to build a registration form. To
I have an MVC3 razor project, which I am trying to build using multiple
I am using form and evaluating it through PHP. Here is my form code:
I am using form base authentication in my Sharepoint site. On my login page
i am using form authentication for my website which is written in ASP.Net, but
Alright, I'm using form.target to open content in a new window. However, when I

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.