php - How to create lists in Symfony? -
i'm new symfony framework. i'd create list of records this:
i need filters @ top, list of items in middle , pagination @ bottom. list should have support both editable , read mode. in read mode user browse data while in edit mode able update values in multiple fields , columns.
since i'll making lot of these lists i'd use interface forms in symfony2 rather tweaking twig templates time.
am missing functionality of symfony forms create lists this? there other common way implement this? can give me hints form related classes extend create support lists?
in order turn symfony forms lists created new form type listtype accepts arbitrary nested collection type. way can create lists various columns. like:
class listtype extends abstracttype { public function buildform(formbuilderinterface $builder, array $options) { if (empty($options['collection_type']) || !$options['collection_type'] instanceof abstracttype) { throw new \invalidargumentexception(); } $builder->add('rows', 'collection', array('type' => $options['collection_type'])); $builder->add('save', 'submit', array('label' => 'save')); } ... }
i'll use $options array provide or turn on , off other features search filter , pagination.
in order have easy interface displaying lists like:
{{ list(list) }}
i created twig extension:
class listextension extends \twig_extension { public function getfunctions() { return array( new \twig_simplefunction('list', array($this, 'listfunction'), array('is_safe' => array('html'), 'needs_environment' => true)) ); } public function listfunction(\twig_environment $env, formview $form) { return $env->resolvetemplate($this->defaulttemplate)->renderblock('list', array('form' => $form)); } ... }
it renders "list" twig block. i'll add other sub blocks same way. extension provides greater feedom "form" blocks.
i registered list extension service:
# app/config/services.yml services: my.twig.list.extension: class: mybundle\twig\extension\listextension arguments: ["::my_theme.html.twig"] public: false tags: - { name: twig.extension }
now have create form of listtype , pass array of row entities.
thanks elias van ootegem pointing me in right direction.
Comments
Post a Comment