$ vi controllers/Api.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Api extends CI_Controller {
public function index()
{
$resp = [];
$resp['a'] = 1;
$this->output->set_content_type('application/json')->set_output(json_encode($resp));
}
}
ブラウザでアクセスしてみる
{"a":1}