简体   繁体   中英

Define post parameters using annotations - Symfony2

I have a controller on a project built on top of Symfony2 and I would like to know if there is a way to define the post method parameters using method annotations similarly to how you can do it for the get method parameters.

I'm not talking about URL parameters - I'm talking about naming the the payload parameters so they get automatically assigned to the method parameters.

/**
 * @Route("/path/{parameter}")
 * @Method("GET")
 */
public function myMethod($parameter){
}

/**
 * @Route("/path/")
 * @Method("POST")
 * @Parameter("parameter") <--- Something like this.
 */
public function myMethod($parameter){
}

Is this feasible with the Sensio bundle or does it only support URL parameters?

Thank you.

The automatic injection of the route placeholders (not GET/POST parameters!) is done by the Symfony framework, it has nothing to do with the Symfony framework.

When the parameter name matches a route attribute name, it'll be injected. This doesn't work for neither POST nor GET parameters. However, you can create your own Parameter Converter (feature of the SensioFrameworkExtraBundle) to make something like this yourself.

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