1

我为它创建了一个自定义表单并将其集成到 easyadmin 中。表格已显示,填写并且操作正在运行,但模板不好:

在此处输入图像描述

这是我的树枝:

    {% extends "@EasyAdmin/page/content.html.twig" %}
{% form_theme form with easyadmin_config('design.form_theme') only %}

{% block body_id 'easyadmin-edit-User-1' %}
{% block body_class 'edit edit-user' %}
{% block content_title %}
        <h1 class="title">Edit Account</h1>
{% endblock %}
{% block content_footer_wrapper '' %}
{% block main %}
    {% block entity_form %}
        {{ form_start(form) }}
        {{ form_widget(form) }}
        <button type="submit" class="btn btn-primary">Update</button>
        {{ form_end(form) }}
    {% endblock entity_form %}
{% endblock %}
{% block body_javascript %}
    {{ include('@EasyAdmin/default/includes/_select2_widget.html.twig') }}
{% endblock %}

和我的控制器:

class UserController extends EasyAdminController
{
    public function editaccountAction(UserInterface $loggedUser, Request $request) {

        $repository = $this->getDoctrine()->getRepository(User::class);
        $id = $loggedUser->getId();
        $entity = $repository->find($id);

        $form = $this->createForm(UserType::class, $entity);

        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            /** @var Article $article */
            $entity= $form->getData();
            $em = $this->getDoctrine()->getManager();
            $em->persist($entity);
            $em->flush();
            $this->addFlash('success', 'Account Saved');
            return $this->redirectToRoute('easyadmin');
        }
        return $this->render('user/editaccs.html.twig', [
            'form' => $form->createView(),
        ]);
    }
}

我怎样才能拥有与编辑相同的表单演示文稿?

4

1 回答 1

0

 {{ form_start(form) }}

添加

{% form_theme form '@EasyAdmin/form/bootstrap_4.html.twig' %}

https://symfony.com/doc/current/form/form_themes.html#applying-themes-to-single-forms

于 2019-12-12T16:57:21.670 回答