Tôi có chỉ mục hành động, in 1) để tạo Thực thể mới; 2) danh sách tất cả các thực thể:Trình điều khiển biểu mẫu nhúng trong mẫu khuôn mẫu: không thể chuyển hướng trong trình điều khiển nhúng sau khi gửi biểu mẫu
public function indexAction()
{
$em = $this->getDoctrine()->getEntityManager();
$entities = $em->getRepository('MyBundle:Entity')->findAll();
return array(
'entities' => $entities,
);
}
Twig:
{% block content %}
{% render "MyBundle:Entity:new" %}
{% render "MyBundle:Entity:list" %}
{% endblock %}
newAction trong Entity Controller là standart điều khiển dạng:
public function newAction()
{
$entity = new Entity();
$form = $this->createForm(new EntityType(), $entity);
$request = $this->getRequest();
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($entity);
$em->flush();
// NOT WORK
return $this->redirect($this->generateUrl('entity_show',
array('id' => $entity->getId())));
}
}
return array(
'form' => $form->createView(),
);
}
Redirect sau khi tổ chức sự bền bỉ đang không hoạt động, báo lỗi:
An exception has been thrown during the rendering of a template
("Error when rendering "http://example.com/app_dev.php/url/"
(Status code is 302).") in MyBundle:Default:index.html.twig at line 2.
Khi bạn đăng lên bộ điều khiển khác, bạn không thể quay trở lại bộ điều khiển hiện tại của mình một cách dễ dàng với dữ liệu biểu mẫu được điền sẵn trong trường hợp có lỗi ... Thiết kế xấu từ Symfony – jsgoupil