У меня есть страница, отображающая пользовательские продукты, пользователь может редактировать продукт. Если пользователь нажмет на кнопку редактирования, он будет перенаправлен на страницу редактирования: http://127.0.0.1/symfony/web/app_dev.php/post/125
Я хотел бы отобразить форму редактирования в модальном режиме, чтобы пользователь не перенаправлялся.Открыть modal с динамическим значением [symfony2]
У меня есть следующее сообщение об ошибке:
An exception has been thrown during the rendering of a template ("The identifier id is missing for a query of Xxx\XxxxxBundle\Entity\Post") in src\Xxx\XxxxxBundle\Resources\views\Post\index.html.twig at line 404.
Моя ссылка была так:
<div class="action">
<a href="{{ path('post_edit', { 'id': entity.id }) }}" class="buttonModal button btn-small full-width">EDIT</a>
</div>
Я изменил его:
<div class="action">
<a href="#" class="buttonModal button btn-small full-width">EDIT</a>
</div>
Это как я делают мой контроллер в моей модальные:
<div class="container">
<div class="row">
<div class="cd-user-modal">
<div class="cd-user-modal-container">
<div id="cd-signup">
<div class="col-sm-12 col-sm-offset-2 form-box">
<div class="form-bottom">
{{render(controller('FLYBookingsBundle:Post:edit')) }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Это форма редактирования:
<form action="{{ path('post_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }}>
{{ form_errors(edit_form) }}
<div class="row">
<div class="col-md-3">
<div class="form-group form-group-lg form-group-icon-left">
<i class="fa fa-phone input-icon"></i>
<label>Phone number</label>
{{ form_widget(edit_form.telephone, {'type':'phone' ,'attr': {'id': 'phone','class': 'form-control phone',} }) }} {{ form_errors(edit_form.telephone) }}
</div>
</div>
<div class="col-md-7">
<div class="form-group form-group-lg form-group-icon-left">
<i class="fa fa-map-marker input-icon"></i>
<label>Address</label>
{{ form_widget(edit_form.address, { 'attr': {'class': 'form-control',} }) }} {{ form_errors(edit_form.address) }}
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-md-3">
{{ form(edit_form) }}
</div>
</div>
</form>
Контроллер листинга страницы:
public function indexAction($user)
{
$user = $this->container->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$findEntities = $em->getRepository('FLYBookingsBundle:Post')->findByBusId($user);
$entities = $this->get('knp_paginator')->paginate($findEntities, $this->get('request')->query->get('page', 1), 5
);
return array(
'entities' => $entities,
'user' => $user,
);
}
Редактировать контроллер:
/**
* Displays a form to edit an existing Post entity.
*
* @Route("/{id}/edit", name="post_edit")
* @Method("GET")
* @Template()
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$user = $this->getUser();
$this->getDoctrine()->getManager()->getRepository('FLYBookingsBundle:Post')->findBy(array('user' => $user));
$entity = $em->getRepository('FLYBookingsBundle:Post')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Post entity.');
}
$editForm = $this->createEditForm($entity);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
);
}
Почему вы удалите '{{путь()}}'? Вы можете использовать его, чтобы получить целевой URL и получить страницу в своем Javascript-коде. –
В любом случае, что такое код в строке 404 из 'src \ Xxx \ XxxxxBundle \ Resources \ views \ Post \ index.html.twig'? –
Код строки 404: '{{render (controller ('FLYBookingsBundle: Post: edit'))}}', Как описано в Hounded, я должен передать параметр в моем рендере, чтобы он выглядел примерно так: '{{ render (controller ('FLYBookingsBundle: Post: edit', {}, {'id': id, 'active': true}))}} '. но у меня есть эта ошибка: 'Variable" id "не существует в src \ FLY \ BookingsBundle \ Resources \ views \ Post \ index.html.twig в строке 404.' – Sirius