LoginSignup
1
1

More than 5 years have passed since last update.

CakePHP3 json出力のヘッダーを指定する

Posted at

'_serialize' とか使わないで、直接自分で json_encode したいような時、ヘッダーが

application/json; charset=UTF-8

になってくれないので以下のように指定する。

    public function jsonOutput()
    {
        $this->autoRender = false;

        $someVariable = .....;

        $this->response->charset('UTF-8');
        $this->response->type('json');
        echo json_encode($someVariable);
    }
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1