Skip to content

Bug: $format in ResourceController is ignored #2828

Description

@rmilecki

Describe the bug
CodeIgniter\RESTful\ResourceController allows (according to the documentation and source code) specifying output format by setting protected $format to xml or json. There is even ResourceController::setFormat helper.

It doesn't work however as $format seems to be ignored.

In practice calling ResponseTrait::respond results in calling ResponseTrait::format which negotiates output format:

$format = $this->request->negotiate('media', $config->supportedResponseFormats, false);

E.g. I get XML when opening page in web browser and JSON when using CLI curl.

CodeIgniter 4 version
4.0.2

Affected module(s)
ResourceController and ResponseTrait::format.

Expected behavior, and steps to reproduce if appropriate

  1. Setting protected $format = 'xml'; should always generate XML response
  2. Setting protected $format = 'json'; should always generate JSON response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions