我为创建了一个自定义表单,并将其集成到easyadmin中。表单已显示,已填写,操作正常,但模板不好:
这是我的Twig:
{% 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(),
]);
}
}
如何才能拥有与编辑相同的表单显示方式?
发布于 2019-12-12 16:57:22
在此之前
{{ 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
https://stackoverflow.com/questions/58770962
复制相似问题