Reputation: 2618
I have a controller action like this:
/**
* @Route("/post/delete/{id}", name="delete_post_modal")
*/
public function deleteAction(Post $post)
{
// ...
}
The annotation @Route
tells symfony to execute method deleteAction
when route matches delete_post_modal
.
All of this works fine.
Question: Is there a way to reverse this functionality and get the route name from method name?
From the example above:
PostController::deleteAction()
(or self::deleteAction
)delete_post_modal
thanks!
Upvotes: 1
Views: 1768
Reputation: 471
try this
update
$router = $this->container->get('router');
foreach ($router->getRouteCollection()->all() as $route => $params)
{
$defaults = $params->getDefaults();
if ( strpos($defaults['_controller'],'PostController::deleteAction') ) {
$myroute = $route;
break;
}
}
Upvotes: 4