Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

let a html button call a Controller Action

Tags:

twig

symfony

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)

like image 870
Christian O. Avatar asked Jun 24 '14 10:06

Christian O.


2 Answers

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)
...
like image 187
Oleksandr Otchenashev Avatar answered Oct 19 '22 00:10

Oleksandr Otchenashev


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

<a href="{{ path('deleteRouteName') }}">Home</a>
like image 5
Rufinus Avatar answered Oct 19 '22 01:10

Rufinus