Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Can I set certain output format for REST?
  • As I interpret, we can set default output format for all REST controllers in the config and we can change this by the extension with an action call, for example, ajax/get_tab.html?num=1

    Can I set stiffly for some action of the REST controller or for all actions of the REST controller certain output format?

    Thank you.
  • One observation. If I use Hybrid (I don't try it in pure REST), I need use prefix 'action_' before 'get' or 'post' etc. It is not documented elsewhere.

    In documentation of REST said:

    You'll notice that instead of the usual "action_" prefix the Rest Controller uses the HTTP method as a prefix.

    http://fuelphp.com/docs/general/controllers/rest.html
  • You can, you don't have to.

    That is true for all controllers, it is a generic feature, not limited to REST. If a "{HTTP_METHOD}_name" method exists, it will be called instead of "action_name". It allows you to split GET and POST processing for standard forms too.

    I don't understand what you mean by "Can I set stiffly..."?
  • >>I don't understand what you mean by "Can I set stiffly..."?

    Independent from extention. It have to always return certain format never see at extension and be used without any extension at all.

    >>you don't have to.

    Is it about prefix 'action_'? But I have tried don't use this prefix - it was not work. It have worked when I add this prefix.

    My version of framework 1.7.
  • Excuse me. I see the section "Format determination". Is it new? May be I have not seen it inadvertently, sorry. It is an answer for my main question.

    But about prefix I am not sure... I'll try it again later.
  • >>I'll try it again later.

    I've tried. It does not work without prefix 'action_'.
  • HarroHarro
    Accepted Answer
    You ALWAYS have to use a prefix.

    The reason for this is simple and two-fold, it avoids collisions with existing PHP function names (you can't have a method called 'list'), and it allows you to define methods that are not callable from the URI.

    So either use the default "action_" prefix, which gets called on any HTTP method request, or use specific HTTP-METHOD prefixes like "get_", "post_", "put_", "delete_" or "patch_" to override the default prefix.

    Note that you can do both. If you define "action_list" and "post_list" in your controller, requesting /controllername/list will call "action_list", posting a form on that page will result in a call to "post_list".

    If you want to know if you can override the format by setting a fixed format using the controller property 'format', that will disable any auto-detection. If auto-detection is enabled, the flow as documented is followed. This is not new, but was added for clarification a few months ago, since more people asked how it exactly works.
  • >>So either use the default "action_" prefix, which gets called on any
    HTTP method request, or use specific HTTP-METHOD prefixes like "get_",
    "post_", "put_", "delete_" or "patch_" to override the default prefix.

    Excuse me for my incompliance, but in Controller extended from Controller_Hybrid in version 1.7 of framwork (my conditions) does not work 'get_' methods and only work 'action_get_'. I just check it once more again.

    But it is not important for me, now... I have another problem 'Connection: keep-alive' on rest response...
  • Oh, shit :)
    I am failed again... stupid idiot :)
    I was called it by 'get_somename.json' url... included 'get_'

    All works as it must. My mistake... Sorry :)

Howdy, Stranger!

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

In this Discussion