cakephp-3.4

How to output custom HTTP body contents with CakePHP 3.4? Echoing causes “Unable to emit headers” error

北城以北 提交于 2019-11-26 23:08:45
Using CakePHP 3.4, PHP 7.0. I'm attempting to do a really simple controller method to output some JSON. It is outputting "Cannot modify headers...". public function test() { $this->autoRender = false; echo json_encode(['method' => __METHOD__, 'class' => get_called_class()]); } Browser output {"method":"App\\Controller\\SomeController::test", "class":"App\\Controller\\SomeController"} Warning (512): Unable to emit headers. Headers sent in file=... Warning (2): Cannot modify header information - headers already sent by (output started at ...) Warning (2): Cannot modify header information -

How to output custom HTTP body contents with CakePHP 3.4? Echoing causes “Unable to emit headers” error

六眼飞鱼酱① 提交于 2019-11-26 08:34:05
问题 Using CakePHP 3.4, PHP 7.0. I\'m attempting to do a really simple controller method to output some JSON. It is outputting \"Cannot modify headers...\". public function test() { $this->autoRender = false; echo json_encode([\'method\' => __METHOD__, \'class\' => get_called_class()]); } Browser output {\"method\":\"App\\\\Controller\\\\SomeController::test\", \"class\":\"App\\\\Controller\\\\SomeController\"} Warning (512): Unable to emit headers. Headers sent in file=... Warning (2): Cannot