PHP Tonic Services - Using the same verb more than once in the same service
I started looking at the Tonic Restful Services framework and I really think it's a very nice framework. The problem is 开发者_如何学运维that I cannot find much resources apart from the examples in order to see possible ways of using it.
I would like for example to know if I could use the POST verb more than one time in a single resource and if there is some sort of annotation that could allow me to do that. For example JAX-RS have the @Action annotation.
I really do not have a lot of experience with REST or PHP so I really need your help.
Thank you in advance.
No, you cannot. But you can route your posts using another variable in your posts requests. Just make sure to clean methods name for security reasons...
something like this.
/**
* Handle a POST request for this resource
* @param Request request
* @return Response
*/
function post($request) {
if (isset($_POST['method'])) {
return $this->$method($request, $name);
}
}
function post_one($request) {
// your code here
}
function post_two($request) {
// your code here
}
//...and so on...
If you want to check if method exists, you could use something like
if (method_exists('controller_name', 'method_name'));
But that's another topic. http://php.net/manual/en/function.method-exists.php
精彩评论