Symfony Form customize array for entity type -
in symfony2.6.6 project have category
entity. don't know how use doctrine tree extension create tree category
entity like:
- category 1
- child category 1
- child category 2
- category 2
- child category 3 ...
now when creating form type creating new category want customize array of parent
field.
the code use
$builder->add('parent', 'entity', array('class' => 'acmeblogbundle:category', 'property' => 'title'));
generates array title expected. want array values append '-' every level of tree. category 1 example '- category 1' , child category 1 '-- child category 1'. how can that?
sorry if has been asked before, don't know how search that.
okay, let's have property getlevel() return current item's level. in category entity file, create simple method, example getindentedtitle thar return pre-defined category based on level.
public function getindentedtitle() { return sprintf( '%s %s', str_repeat('-', $this->getlevel()), $this->gettitle() ); }
the following code add many "-" symbols current category level , append title next it.
then in form builder, have specify use method:
$builder->add('parent', 'entity', array('class' => 'acmeblogbundle:category', 'property' => 'indentedtitle'));
more info on str_repeat.
hope got idea.
Comments
Post a Comment