yavin/symfony-form-tree
最新稳定版本:v1.0.2
Composer 安装命令:
composer require yavin/symfony-form-tree
包简介
create select field with indentation for tree structure
README 文档
README
This extension provide displaying doctrine tree entity types in synfony forms. It add a prefix to option names in select list that indicates tree level.
It is tested and should work with symfony 3.0+
If want to use this in symfony 2 look at "symfony-2" branch of this extension
<select name="..." data-level-prefix="-"> <option value="1">Motors</option> <option value="2">Electronics</option> <option value="3">-Cell phones</option> <option value="4">--Samsung</option> <option value="5">-Computers</option> <option value="6">Fasion</option> </select>
Instalation
-
With composer.json
composer require yavin/symfony-form-tree:^1.0 -
Add type guesser in your services file (optional):
<service class="Yavin\Symfony\Form\Type\TreeTypeGuesser"> <argument type="service" id="doctrine"/> <tag name="form.type_guesser"/> </service>
or if you use
ymlformat:services: symfony.form.type_guesser.tree: class: Yavin\Symfony\Form\Type\TreeTypeGuesser arguments: [ "@doctrine" ] tags: - { name: form.type_guesser }
-
Then add field to tree model. In this example
use Yavin\Symfony\Form\Type\TreeType; public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('category'); //extension will guess field type //or this is full example with default options: $builder->add('category', TreeType::class, [ 'class' => Category::class, // tree class 'levelPrefix' => '-', 'orderFields' => ['treeLeft' => 'asc'], 'prefixAttributeName' => 'data-level-prefix', 'treeLevelField' => 'treeLevel', ]); }
This extension assume that in tree model You have
treeLeftandtreeLevelfields. It can be changed in field options.Here is example tree entity.
Other
License
统计信息
- 总下载量: 91.02k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-12-20
