当前位置: 动力学知识库 > 问答 > 编程问答 >

symfony2 - let a html button call a Controller Action

问题描述:

How can I make my html Button

(like <button type="button" class="btn btn-warning btn-xs">delete</button>)

call a Controller Action like deleteAction($project)

from within my twig code?(or with java script)

网友答案:

In twig template

<a href="{{ path('delete_route_name', {'id': entity.id }) }}">Delete</a>

On your controller

/**
 * @param User $entity
 *
 * @Route("/{id}/entity-remove", requirements={"id" = "\d+"}, name="delete_route_name")
 * @return RedirectResponse
 *
 */
public function deleteActionName(User $entity)
...
网友答案:

see http://symfony.com/doc/current/book/templating.html#linking-to-pages

<a href="{{ path('deleteRouteName') }}">Home</a>
分享给朋友:
您可能感兴趣的文章:
随机阅读: