2.1Symfony路由(Routing)之基础(Basic)

路由句法

@Route("/product", methods={"GET","HEAD"}, name="product_index")

路由表

HTTP VerbPathController#Actionname
GET/productproduct#indexproduct_index
GET/product/newproduct#newproduct_new
POST/productproduct#createproduct_create
GET/product/{id}product#showproduct_show
GET/product/{id}/editproduct#editproduct_edit
PATCH/PUT/product/{id}product#updateproduct_update
DELETE/product/{id}product#deleteproduct_delete

子域路由

@Route("/", name="mobile_homepage", host="m.example.com")

本地化路由

/**
 * @Route({
 *     "en": "/about-us",
 *     "nl": "/over-ons"
 * }, name="about_us")
 */
public function about(): Response
{
    // ...
}

YAML路由

# config/routes.yaml
blog_list:
    path: /blog
    controller: App\Controller\BlogController::list

原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/php/symfony/6708.html

发表评论

登录后才能评论