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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:54:55+00:00 2026-06-14T09:54:55+00:00

I’m trying to migrate my flat php project to Symfony2, but its coming to

  • 0

I’m trying to migrate my flat php project to Symfony2, but its coming to be very hard.
For instance, I have a table of Products specification that have several specifications and are distinguishables by its “cat” attribute in that Extraspecs DB table.
Therefore I’ve created a Entity for that table and want to make an array of just the specifications with “cat” = 0…

I supose the code is this one.. right?

$typeavailable = $this->getDoctrine()
        ->getRepository('LabsCatalogBundle:ProductExtraspecsSpecs')
        ->findBy(array('cat' => '0'));

Now how can i put this in an array to work with a form like this?:

form = $this ->createFormBuilder($product)
->add('specs', 'choice', array('choices' => $typeavailableArray), 'multiple' => true)  

Thank you in advance 🙂

#

Thank you all..

But now I’ve came across with another problem..
In fact i’m building a form from an existing object:

$form = $this ->createFormBuilder($product)
                ->add('name', 'text')
                ->add('genspec', 'choice', array('choices' => array('0' => 'None', '1' => 'General', '2' => 'Specific')))
                ->add('isReg', 'choice', array('choices' => array('0' => 'Material', '1' => 'Reagent', '2' => 'Antibody', '3' => 'Growth Factors', '4' => 'Rodents', '5' => 'Lagomorphs')))

So.. in that case my current value is named “extraspecs”, so i’ve added this like:

->add('extraspecs', 'entity', array(
                        'label'          => 'desc',
                        'empty_value'    => ' --- ',
                        'class'          => 'LabsCatalogBundle:ProductExtraspecsSpecs',
                        'property'       => 'specsid',
                        'query_builder'  => function(EntityRepository $er) {
                            return $er ->createQueryBuilder('e');

But “extraspecs” come from a relationship of oneToMany where every product has several extraspecs…

Here is the ORM:

Labs\CatalogBundle\Entity\Product:
    type: entity
    table: orders__regmat
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        name:
            type: string
            length: 100
        catnumber:
            type: string
            scale: 100
        brand:
            type: integer
            scale: 10
        company:
            type: integer
            scale: 10
        size:
            type: decimal
            scale: 10
        units:
            type: integer
            scale: 10
        price:
            type: decimal
            scale: 10
        reqcert:
            type: integer
            scale: 1
        isReg:
            type: integer
            scale: 1
        genspec:
            type: integer
            scale: 1

    oneToMany:
        extraspecs:
            targetEntity: ProductExtraspecs
            mappedBy: product

Labs\CatalogBundle\Entity\ProductExtraspecs:
    type: entity
    table: orders__regmat__extraspecs

    fields:
        extraspecid:
            id: true
            type: integer
            unsigned: false
            nullable: false
            generator:
                strategy: IDENTITY
        regmatid:
            type: integer
            scale: 11
        spec:
            type: integer
            scale: 11
        attrib:
            type: string
            length: 20
        value:
            type: string
            length: 200

    lifecycleCallbacks: {  }


    manyToOne:
      product:
        targetEntity: Product
        inversedBy: extraspecs
        joinColumn:
            name: regmatid
            referencedColumnName: id

HOw should I do this?

Thank you!!!

  • 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-14T09:54:56+00:00Added an answer on June 14, 2026 at 9:54 am

    The values returned from the database are already in an array.

    You can use the entity field type to create the form you want.
    This is how it works:

    $form = $this->createFormBuilder($product)
        ->add('specs', 'entity', array(
            'class' => 'LabsCatalogBundle:ProductExtraspecsSpecs',
            'choices' => $typeavailable,
            'property' => 'specsid',
            'multiple' => true,
        ))->getForm();
    

    Replace the property attribute for a field in the target entity (ProductExtraspecsSpecs) that you want to be displayed in the form.

    If something is still unclear to you just ask and I will try to supply additional information.

    To have the current objects selected do this:
    In the controller: $selected = $product->getExtraspecs();

    In the form builder:

    $form = $this->createFormBuilder($product)
        ...
        ->add('specs', 'entity', array(
            'data' => $selected,
            ...
        ))->getForm();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I'm trying to select an H1 element which is the second-child in its group
I'm trying to create an if statement in PHP that prevents a single post
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put

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.