简体   繁体   English

Symfony2-是否可以创建独立的表单集合?

[英]Symfony2 - Is it possible to create a standalone collection of forms?

I have a table of data I want to be able to edit row-by-row. 我有一个数据表,希望能够逐行进行编辑。 The most sensible thing do do would be to have each row be its own form. 最明智的做法是使每一行都具有自己的形式。 Can I do that in Symfony2 without a linked parent entity? 没有链接的父实体,我可以在Symfony2中这样做吗? The documentation only shows how to do it with a parent. 文档仅显示如何与父母一起做。

Your controller action: 您的控制器动作:

    public function gridAction( $criteria ) {
        $entities = $this->getDoctrine()
        ->getManager()
        ->getRepository( 'Bundle:Entity' )
        ->findbyCriteria( $criteria );
        // criteria presumably involves some gneration from routing 
        // and may not be a parameter at all

        if ( array() != $entities->toArray() ) {
            throw 
            $this->createNotFoundException( 'Unable to find any entities.' );
        }

        $forms = array_map(function($element) use ($this) {
            return $this->createForm(new EntityType()
                , $element
                , array()  // form parameters here
                );
        });

        return $this->render( 'Bundle:Entity:grid.html.twig'
            , array(
                'forms'          => $forms
            ) );
    }

And your twig: 和你的树枝:

<table class="records_list dataTable" id="CaseloadTable">
    <thead>
        <tr>
        </tr>
    </thead>
    <tbody>
        {% for form in forms %}
        <tr>
            {{form_widget(form)}}
        </tr>   
        {% endfor %}
    </tbody>
</table>

However, you might be better served looking at this: https://github.com/Abhoryo/APYDataGridBundle 但是,最好看一下: https//github.com/Abhoryo/APYDataGridBundle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM