Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
REST controller
  • is there a way to set the overall name of a json call when using the rest controller. I have the following

    class Controller_Transaction extends Controller_Rest{

        public function get_index()
        {
           
            return $this->response( Model_Transaction::find('all'));

        }

    output gives
    {"1":{"id":"1","personal_id":"1","type":"update","debit":"500","credit":"100","shopcode":"1","created_at":"1393773869","updated_at":"1393773869"},"2":{"id":"2","personal_id":"2","type":"try","debit":"5","credit":"5","shopcode":"90","created_at":"1393792862","updated_at":"1393792862"}}

    is there away of making my json call indicate the table name it is coming from.

    Thanks in advance


  • What do you mean? You already know it's a list of transactions?
  • I would like a situation, were I am able to parse the root name of the json tree like below were name is the root of the json.

    {"Name":["1" :"a","2";"b",{"recom":["a","b"]}]}

    When I use the Rest_Controller, the Root Name  is being left out.

    in this case it will output something like

    "1" :"a","2";"b",{"recom":["a","b"]}
  • SyntaxlbSyntaxlb
    Accepted Answer
    Just do 

    return $this->response(array('Name' => Model_Transaction::find('all')));

Howdy, Stranger!

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

In this Discussion