Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How can I create a RESTful method within one of my regular controllers?
  • I have a controller that extends the base controller. It already implements several non-restful actions. I'd like to add a method to this controller that is intended to return RESTful responses. So far, it does not seem to be working - using Chrome's network console, it appears that the controller is attempting to send back an entire template. How can I prevent this from happening? Here is my code - note that it is just a shim so far for testing: public function action_submit()
    {
    $this->response->set_header('Content-Type', 'application/json');
    $this->response->body(json_encode(array('success' => TRUE)));
    } How can I actually force it to return just this, without the template? EDIT: I'd just like to add that, if possible, I'd prefer to avoid creating a new controller that extends the restful controller. I just need this one, simple method, and it makes the most sense in the context of my existing controller. I'll create a new one that extends the restful controller if I absolutely have to, but I would really prefer to avoid it.
  • Are you extending the base controller or the template controller? If you are extending the template controller you can just omit it from the method : http://docs.fuelphp.com/general/controllers/template.html#/omit_methods

Howdy, Stranger!

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

In this Discussion