代码之家  ›  专栏  ›  技术社区  ›  Blackbam

Symfony@Route注释(与HTML 5路由器结合):如何匹配某个路径之后的所有路径?

  •  0
  • Blackbam  · 技术社区  · 6 年前

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

    让symfony匹配任何路线( .com/secured/something ; .com/secured/anything/else

    symfony支持这个吗?我想不出搜索这个的条件。

    /secured )?

    0 回复  |  直到 10 年前
        1
  •  6
  •   malcolm    10 年前
    /**
     * @Route("/secured/{anything}", name="_secured", defaults={"anything" = null}, requirements={"anything"=".+"})
     */
    
    public function securedAction($anything){
        //return secured JS frontend 
    }
    

    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" ]
    

    之后的一切 将是一个参数 $anything