路由及路由规则,请求方式

  1. 路由文件指定

     # [项目路径]/app/config/routing.yml
    
     # 路由规则绑定注释
     xxx:
         resource: "@XxxBundle/Controller/"
         type:     annotation
         prefix:   /[整个XxxBundle所有控制器方法路由前缀]
    
     # 路由规则绑定yml
     xxx:
         resource: "@XxxBundle/Resources/config/routing.yml"
         prefix:   /[整个XxxBundle所有控制器方法路由前缀]
    
     # 路由规则绑定xml
     xxx:
         resource: "@XxxBundle/Resources/config/routing.xml"
         prefix:   /[整个XxxBundle所有控制器方法路由前缀]
    
  2. annotation

     # [项目路径]/src/XxxBundle/Controller/XxxController.php
     # Route用于指定路由名、路由规则,Method用于限定允许请求的方式
     use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
     use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
    
     class XxxController extends Controller
     {
         /**
          * 路由("/路由路径/{参数1}/{参数2}.{参数3}", name="路由别名", defaults={"参数1": "默认值", "参数2": "默认值"}, requirements={"参数2": "正则", "参数3": "正则"})
          * @Route("/{route}/{age}.{format}", name="show", defaults={"route": "api"}, requirements={"age": "\d+", "format": "html|php"})
          * @Method({"POST", "GET"})
          */
         public function showAction($route, $age, $format)
         {
             ...
         }
     }
    
  3. yml

     # [项目路径]/src/XxxBundle/Resources/config/routing.yml
     show:
         path:     /{route}/{age}.{format}
         defaults: { _controller: XxxBundle:Xxx:show, route: api }
         requirements:
             age: \d+
             format:  html|php
    
  4. xml

     # [项目路径]/src/XxxBundle/Resources/config/routing.xml
     <?xml version="1.0" encoding="UTF-8" ?>
     <routes>
         <route id="show" path="/{route}/{age}.{format}">
             <default key="_controller">XxxBundle:Xxx:show</default>
             <default key="route">api</default>
             <requirement key="age">\d+</requirement>
             <requirement key="format">html|php</requirement>
         </route>
     </routes>
    
@耿志环 2012-∞ 冀ICP备17033181号, powered by Gitbook修订: 2018-05-23 16:25:59

results matching ""

    No results matching ""