我希望基本上得到与Twig的功能路径(routeName)相同的结果,但不能在 view.html.twig 中但在控制器内部本身。
routing.yml :
MyBundle_route_first:
pattern: /dummy/first/{foo}
defaults: { _controller: MyBundle:Dummy:First }
requirements:
_method: GET
foo: \d+
MyBundle_route_second:
pattern: /dummy/second/{foo}/{bar}
defaults: { _controller: MyBundle:Dummy:Second }
requirements:
_method: GET
foo: \d+
bar: \d+
controller.php :
class DummyController extends Controller {
public function firstAction($foo) {
// do some stuff
}
public function secondAction($foo, $bar) {
// do some stuff
}
public function anotherAction() {
$firstRoutePattern = some_magic_function("MyBundle_route_first");
// "/dummy/first/{foo}"
$secondRoutePattern = some_magic_function("MyBundle_route_second");
// "/dummy/second/{foo}/{bar}"
}
}
任何有关相关主题的帮助或链接都会有很多不足之处。
祝你有个美好的一天: - )
答案 0 :(得分:2)
请看这个方法:generate
$firstRoutePattern = $this->container->get('router')->generate('MyBundle_route_first', array('foo' => $foo));