Search code examples
restler

Dynamic return status from restler


If I put an @status 201 in my function comments then that's what gets returned always on success. Is there a way to make that dynamic?

For example, I have a putChild($child_id, $team_id) method defined. If the child is not already on the team, then I insert them and return a 201. If they are already on the team though, I just don't do anything. In that case I'd want a 200 status to go back, not a 201.

Not sure how to handle this situation.


Solution

  • With the latest version in the v3 branch, you can do the following in the api method to override the status code at runtime

    $this->restler->responseCode = 201;