$controller->forward(...)
需要形式为
MyBundle:Controller:action
的字符串,但我只有路由名称。如何转发请求的路线名称?
最佳答案
这个问题很古老,但是出于说明目的,对于这里的所有Google员工来说,这都是一种解决方法。
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'];
}
}
关于symfony - 如何转发请求到路线名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17493670/