简体   繁体   中英

Set route's allowed methods with annotation when using FOSRestBundle

I'm wondering if there's an easy way to alter allowed methods for routes generated via FOSRestBundle using type: rest in routing.yml :

For example I have:

public function regularAction()
{
}

which is transformed into:

Name                             Method     Scheme   Host   Path
-------------------------------- ---------- -------- ------ -----------------------
pria_core_regular                GET        ANY      ANY    /regular.{_format}

I can change the path generated with FOS\\RestBundle\\Controller\\Annotations\\Route\\Method annotation:

/**
 * @Route("/test-regular")
 */
public function regularAction()
{
}

Then the route is as I expected:

Name                             Method     Scheme   Host   Path
-------------------------------- ---------- -------- ------ -----------------------
pria_core_regular                GET        ANY      ANY    /test-regular.{_format}

However I can't do the same with overriding allowed methods. For example:

@Method({"GET", "POST"})

Using @Method has no effect. Is this intentionally disabled by FOSRestBundle?

In order to set the request methods, please implement your routes like this:

// Get Action
public function getRegular() {}

// Post Action 
public function postRegular() {}

Edit: Apologies, I didn't understand the question 100%, prepending your controller method with get/post etc will set the methods, please see here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM