Symfony路由:匹配第一个节点后的任何内容

The*_*rby 2 php routing symfony

我想做这样的事情:

/**
 * @Route("^/secured") <-- this would not work, just an example
 */
public function securedAction(){
  //return secured JS frontend 
}
Run Code Online (Sandbox Code Playgroud)

并使symfony匹配任何路由(.com/secured/something; .com/secured/anything/else)到这一个动作,而不手动定义所有路由.

symfony支持这个吗?我想不出用来搜索这个的术语.

如何在不根据第一个节点(/secured)手动定义所有路由的情况下匹配和路由到此控制器操作?

mal*_*olm 5

/**
 * @Route("/secured/{anything}", name="_secured", defaults={"anything" = null}, requirements={"anything"=".+"})
 */

public function securedAction($anything){
    //return secured JS frontend 
}
Run Code Online (Sandbox Code Playgroud)

name - 只是路线的名称.

defaults - 如果你没有在网址中提供参数,你可以在这里设置参数的默认值: /secured/

requirements- 参数的要求,在这种情况下anything可以包含正斜杠:http://symfony.com/doc/current/cookbook/routing/slash_in_parameter.html,但您必须自己在控制器操作中处理它:

例如,如果您提供网址: /secured/anything/another_thing/one_more_thing

你可以得到所有参数 explode('/', $anything);

结果将是:

array:3 [
  0 => "anything"
  1 => "another_thing"
  2 => "one_more_thing" ]
Run Code Online (Sandbox Code Playgroud)

之后的所有内容都/secured/将是一个参数$anything.