0

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? The documentation only shows how to do it with a parent.

4

1 回答 1

1

您的控制器操作:

    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
            ) );
    }

还有你的树枝:

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

但是,您可能会得到更好的服务: https ://github.com/Abhoryo/APYDataGridBundle

于 2013-04-17T16:38:55.403 回答