$controller->forward(...)
requires a string in form or MyBundle:Controller:action
, but I only have route name.
How to forward request to route name?
this question is old but for the sake of documentation and for all the googlers out there here is one way of doing it.
class Mycontroller extends Controller {
public function indexAction(){
$response = $this->forward($this->routeToControllerName('ROUTE_NAME_HERE'));
}
private function routeToControllerName($routename) {
$routes = $this->get('router')->getRouteCollection();
return $routes->get($routename)->getDefaults()['_controller'];
}
}
Redirect to route name 'homepage':
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class TaskController extends AbstractController
{
public function goHome()
{
return $this->redirectToRoute('homepage');
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With