Upgrade Output Class

Documentations

What has been changed

  • The Output class has been changed to the Response class.

  • The methods have been renamed.

Upgrade Guide

  1. The methods in the HTTP Response class are named slightly different. The most important change in the naming is the switch from underscored method names to camelCase. The method set_content_type() from version 3 is now named setContentType() and so on.

  2. In the most cases you have to change $this->output to $this->response followed by the method. You can find all methods in HTTP Responses.

Code Example

CodeIgniter Version 3.x

<?php

$this->output->set_status_header(404);

// ...

$this->output
    ->set_content_type('application/json')
    ->set_output(json_encode(array('foo' => 'bar')));

CodeIgniter Version 4.x

<?php

$this->response->setStatusCode(404);

// ...

return $this->response->setJSON(['foo' => 'bar']);