Welcome Guest, Not a member yet? Register   Sign In
Formatting REST response in JSON
#1

So, I'm trying to follow the docs here:

https://codeigniter.com/user_guide/incom...stful.html

In my extended ResourceController I'm setting $format = 'json', but I always get XML.

I've run through the code of ResourceController.php, ResponseTrait.php and Negotiate.php and I can see nowhere where this property is actually used to decide the response format!

As it stands it seems like the headers are always used to determine the response.

Can anyone confirm or explain where I may have messed up?

Here's the relevant code:

<?php namespace App\Controllers;

use CodeIgniter\RESTful\ResourceController;

class Salutation extends ResourceController
{
    protected $modelName = 'App\Models\SalutationModel';
    protected $format    = 'json';

    public function index()
    {
        // print '<pre>'; print_r($this->model->asArray()->findAll()); exit;
        // $this->setFormat("json");
        return $this->respond($this->model->findAll());
    }


 
Reply


Messages In This Thread
Formatting REST response in JSON - by neilpopham - 11-04-2020, 07:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB