Monday 15 August 2011

php - Get Categories from SonataClassificationBundle as Dropdown in SonataBlockBundle block -


I am trying to get a dropdown of all categories in a custom SonataClassificationBundle Sonata Block Bundle Block

Right now, I am building a class tree in my block class. this is not right. But I do not know how to configure my form to do this form automatically.

I'm currently using:

  $ categories = $ this- & gt; CategoryManager - & gt; GetCategories ('default'); If (Function_exists ('buildCategoryTreeRecursive')) {function buildCategoryTreeRecursive ($ ranges, $ buffer = zero, $ level = 0) {if ($ buffer == empty) {$ buffer = array}; } Forex Currency ($ Category as Category $) {$ Buffer [$ Category-> GetId ()] = str_repeat ('-', $ level). ($ Level & gt; 0? '': '') $ Category- & gt; GetName (); $ Children = $ Category-> Meet children (); $ Buffer = build credited credits ($ children, $ buffer, $ level + 1); } $ Buffer returned; }} $ CategoryTree = buildCategoryTreeRecursive ($ ranges); $ FormMapper-> The array ('settings', 'sonata_type_immutable_array', array ('key' = & gt; array (array ('title', 'text', array ('required' = & gt; true)), array ('category' 'Choice', array ('required' = & gt; true, 'option' => $ range trilogy)), Arabic ('required' = & gt; wrong))); }  

I hope that the code:

  $ formMapper-> Array ('settings', 'sonata_type_immutable_array', array ('key' = & gt array ('title', 'text', array ('required' => true)), array ('subtitle', 'text' , Array ('required' = & gt; wrong)), array ('square'),)));  

The category is defined as:

  / ** * @ORM \ manyToOne (targetEntity = "application \ sonata \ classification \ unit \ Class ") * @ORM \ JoinColumn (name =" category_id ", referenced column name =" id ") * / protected $ category;  

And when I use it in Sonata \ AdminBundal \ Administrator \ Admin \ subclass (a dropdown is generated):

 < Code> Protected function configured form field ($ formMapper $ formMapper) {$ formMapper - & gt; From ('Content') - & gt; Addition ('Category') - & gt; the ending (); }  


No comments:

Post a Comment