symfony - Creating array from an object in symfony2 -


I am trying to access a list of those categories in a database and put them in a form in Symfony2 .

  Public function ProductAdaction () {$ product = new product (); $ Ranges = $ this- & gt; GetDoctrine () - & gt; GetRepository ('Auditors Shopsbundle: Category') - & gt; FindAll (); $ Form = $ this- & gt; CreateFormbuilder ($ product) - & gt; Addition ('name', 'text') - & gt; add ('name', 'text') - 'junk' ('category', 'likes', array ('option' = & gt; $ categories, / * ('Save', 'Submit', array ('label' = & gt; create a job ')) - & gt; getForm ($) --- $ $ (AudsurAdminBundle: default: new.html.twig) Return the array ('form' => gtc: $ form->; createView (),);}  

How can I go from $ ranges to an object, Can I put in the section, and what does the function expect?

  -> Junk ('category', 'likes', sir ('Options' = & gt; $ categories; / * This is incorrect * / 'multiple' = & gt; False,))  

I know it's basic, but I The right keywords can not be found to find the answer (What do I want?)

First of all, It is wrong "There is not a specific error message to help you too much, it is saying that" my code does not work "and why not telling it ahead of its actual problem Dhte the ..

If you are not using the right type of handling unit type and display it properly. As the @Tallas, you need the field type class parameter and property parameters (assuming that you did not write __ toString () There is nothing like, the function in the unit square.)

  $ categories = $ this-> getDoctrine () - & gt; GetRepository ('AudsurShopBundle: Category') - & gt; FindAll (); $ Form = $ this- & gt; CreateFormBuilder ($ product) - & gt; Add ('category', 'unit', array ('class' = & gt; 'oddshoor shop bundle: category', 'option' => $ ranges, 'many' = & gt; wrong, 'property' = & Gt; 'name', // it needs to be a real property, I have just assumed the name)) - & gt; Junk ('name', 'text') - & gt; ('Save', 'Submit', array ('label' = & gt; create job ')) - & gt; GetForm ();  

Since you are all in the category , the findAll () query is not really necessary. You can go for it instead:

  $ form = $ this- & gt; CreateFormBuilder ($ product) - & gt; Addition ('Category', 'unit', array ('class' = & gt;' objects shops: 'category', 'multi' = & gt; false, 'property' = & gt; 'name', // Property needs to be, I have just assumed the name)) - & gt; Plus ('name' 'text') - & gt; Add ('Save', 'Submit', array ('label' = & gt; create job ')) - & gt; GetForm ();  

If you are looking for a specific subset of categories, then you can use the options property as before.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -