什么是路由
路由就是一个可以将url和控制器中的方法进行关联的映射,它可以通过配置文件进行修改。
在config/routes.yaml可以添加配置路由。
app_lucky_number:
path: /lucky/number
controller: App\Controller\LuckyController::number
配置路由
可以通过配置注解来进行路由
- 引入注解路由
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
网友评论