Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM overriding httpcode on REST controller
  • Hi everybody!
    I was playing with the ORM and a REST Controller, and I stumble into an issue.
    Even if I specify the httpcode for the response, the ORM will override it on failure.
    example: $this->response('',500);
    on success I don't have any issue.
    Does anyone have any Idea?
    (you can see the code below)
    Thanks!
    try
            {
                $user = new Model_user($data); 
                $user->save();
                $this->response($data,201);
            }
            catch(Orm\ValidationFailed $e)
            {
                $this->response('',500);      
            }
    
  • The ORM will return httpcode 404 everytime on failure
  • I fail to see the relationship between the ORM and an HTTP status code. If an ORM method call fails, and you catch the exception thrown, you can do with it what you want. If you don't catch it (either because you didn't code the catch, or you made an mistake), you'll end up with an error generated by the framework, which will set a 500 status code unless HTTP headers are already sent. Note however that the rest controller will set a 404 status if either the method requested does not exist, or if there is no data to be returned (and that seems to be the case if your ORM call fails). If you want a 500 status code instead, set the $no_data_status property of your REST controller to 500.
  • That was it, I was returning an empty string...
    Thank you very much for your time and Help

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion