美文网首页
symfony路由

symfony路由

作者: 追梦人在路上不断追寻 | 来源:发表于2021-06-09 09:01 被阅读0次

    什么是路由

    路由就是一个可以将url和控制器中的方法进行关联的映射,它可以通过配置文件进行修改。

    在config/routes.yaml可以添加配置路由。

    app_lucky_number:
        path: /lucky/number
        controller: App\Controller\LuckyController::number
    

    配置路由

    可以通过配置注解来进行路由

    1. 引入注解路由
     composer require annotations
    

    2.在控制器中添加注释,进行注解

      // src/Controller/LuckyController.php
    
      // ...
    + use Symfony\Component\Routing\Annotation\Route;
    
      class LuckyController
      {
    +     /**
    +      * @Route("/lucky/number")
    +      */
          public function number()
          {
              // this looks exactly the same
          }
      }
    

    查看路由

    php bin/console debug:router
    

    相关文章

      网友评论

          本文标题:symfony路由

          本文链接:https://www.haomeiwen.com/subject/gnwseltx.html