Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 仅在集合的第一行中显示Symfony呈现窗体_Php_Forms_Symfony_Html Table - Fatal编程技术网

Php 仅在集合的第一行中显示Symfony呈现窗体

Php 仅在集合的第一行中显示Symfony呈现窗体,php,forms,symfony,html-table,Php,Forms,Symfony,Html Table,也许有人可以帮助我,因为我从一周前开始就在挖掘论坛和文档,如何呈现我在第三栏有表单的表格 我有一个带有以下代码段的CollectionController类: return $this->render( 'vollmachtapp/pages/collections/list2.html.twig', [ 'attachmentForm' => $attachmentForm->createView(),

也许有人可以帮助我,因为我从一周前开始就在挖掘论坛和文档,如何呈现我在第三栏有表单的表格

我有一个带有以下代码段的CollectionController类:

return $this->render(
        'vollmachtapp/pages/collections/list2.html.twig',
        [
            'attachmentForm' => $attachmentForm->createView(),
            'list' => $apiClient->listAllVollmachten()
        ]
    );
附件表单如下所示:

$attachmentForm = $this->createForm( SimpleAttachmentType::class, $attachment );
以下是我的SimpleAttachmentType:

class SimpleAttachmentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
  {
    $builder
        ->add('file', FileType::class)
        ->add('vollmachtId', HiddenType::class)
        ->add('save', SubmitType::class, ['label' => 'Vollmacht hochladen']);
  }
}
现在我用的是一根树枝,看起来像:

<table id="datatable" class="table table-striped table-bordered">
                    <thead>
                    <tr>
                        <th>Vollmacht ID</th>
                        <th>Users</th>
                        <th>Upload/Download</th>
                    </tr>
                    </thead>

                    <tbody>

                        {% for collection in list.items %}
                            <tr>
                                <td>{{ collection.id }}</td>
                                <td>
                                    {% for user in collection.users %}
                                        <a href="{{ url('user_detail', {'id': user.id}) }}">
                                            {{ user.name }}
                                        </a><br>
                                    {% endfor %}
                                </td>
                                <td>
                                    <a href="{{ url('downloadVollmacht', {'id': user.id}) }}"><button type="button" class="btn btn-sm btn-primary">Download Vollmacht</button></a>
                                    {% if(app.user.role == "admin") %}
                                    <hr>
                                    <div class="text-center mtop20">
                                        {{ form_start(attachmentForm, {method: 'POST'}) }}
                                            {% if not attachmentForm.vars.valid %}
                                                <div class="alert alert-danger alert-dismissible fade in" role="alert">
                                                    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
                                                    {{ form_errors(attachmentForm.file) }}
                                                </div>
                                            {% endif %}
                                            {{ form_widget(attachmentForm.vollmachtId, {'name': vollmachtId, 'value': collection.id}) }}
                                            {{ form_widget(attachmentForm.file) }}
                                            <br />

                                            {{ form_widget(attachmentForm.save, {attr: {'class': 'btn-left btn btn-sm btn-primary'}}) }}
                                        {{ form_end(attachmentForm) }}
                                    </div>
                                    {% endif %}
                                </td>
                            </tr>
                        {% endfor %}

                    </tbody>
                </table>

Vollmacht ID
使用者
上传/下载
{list.items%中集合的%s}
{{collection.id}
{%用于集合中的用户。用户%}

{%endfor%} {%if(app.user.role==“admin”)%}
{{form_start(attachmentForm,{method:'POST'}}}} {%如果不是attachmentForm.vars.valid%} × {{form_errors(attachmentForm.file)} {%endif%} {form_小部件(attachmentForm.vollmachtId,{'name':vollmachtId,'value':collection.id}}} {{form_小部件(attachmentForm.file)}
{form_小部件(attachmentForm.save,{attr:{'class':'btn left btn btn btn sm btn primary'}}}} {{form_end(attachmentForm)} {%endif%} {%endfor%}
我的问题是,表单只在表的第一行呈现。有人能告诉我我做错了什么,我必须改变才能让它工作吗

谢谢并致以最良好的祝愿,
Michael Obster

您应该了解如何使用symfony文档中的表单集合:


您的主要问题是,无法多次分离此表单片段

{{ form_start(attachmentForm, {method: 'POST'}) }}
您的表单开始和表单结束必须包裹孔表单。如果您希望在所有标记中也包含该表单,则不能仅在一个标记中编写开始表单细枝片段。您必须编写如下代码:

<table id="datatable" class="table table-striped table-bordered">
                <thead>
                <tr>
                    <th>Vollmacht ID</th>
                    <th>Users</th>
                    <th>Upload/Download</th>
                </tr>
                </thead>

                <tbody>                 
                        {% for collection in list.items %}
                            <tr>
                                {{ form_start(attachmentForm, {method: 'POST'}) }}
                                <td>{{ collection.id }}</td>
                                <td>
                                    {% for user in collection.users %}
                                        <a href="{{ url('user_detail', {'id': user.id}) }}">
                                            {{ user.name }}
                                        </a><br>
                                    {% endfor %}
                                </td>
                                <td>
                                    <a href="{{ url('downloadVollmacht', {'id': user.id}) }}"><button type="button" class="btn btn-sm btn-primary">Download Vollmacht</button></a>
                                    {% if(app.user.role == "admin") %}
                                    <hr>
                                    <div class="text-center mtop20">

                                            {% if not attachmentForm.vars.valid %}
                                                <div class="alert alert-danger alert-dismissible fade in" role="alert">
                                                    <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
                                                    {{ form_errors(attachmentForm.file) }}
                                                </div>
                                            {% endif %}
                                            {{ form_widget(attachmentForm.vollmachtId, {'name': vollmachtId, 'value': collection.id}) }}
                                            {{ form_widget(attachmentForm.file) }}
                                            <br />

                                            {{ form_widget(attachmentForm.save, {attr: {'class': 'btn-left btn btn-sm btn-primary'}}) }}

                                    </div>
                                    {% endif %}
                                </td>
                                {{ form_end(attachmentForm) }}
                            </tr>                               
                        {% endfor %}
                </tbody>
            </table>

Vollmacht ID
使用者
上传/下载
{list.items%中集合的%s}
{{form_start(attachmentForm,{method:'POST'}}}}
{{collection.id}
{%用于集合中的用户。用户%}

{%endfor%} {%if(app.user.role==“admin”)%}
{%如果不是attachmentForm.vars.valid%} × {{form_errors(attachmentForm.file)} {%endif%} {form_小部件(attachmentForm.vollmachtId,{'name':vollmachtId,'value':collection.id}}} {{form_小部件(attachmentForm.file)}
{form_小部件(attachmentForm.save,{attr:{'class':'btn left btn btn btn sm btn primary'}}}} {%endif%} {{form_end(attachmentForm)} {%endfor%}

但是,可能需要重新构建一点HTML标记。

谢谢,我会试试的。我想我现在明白这个问题了。