about this or response

excuse me

<?php
use Phalcon\Mvc\Controller;

class ApiController extends Controller {
  public function machineAction() {
    $this->jsonAction(['code' => '0']);
  }
  public function notfoundAction() {
    $this->response->setContentType('application/json', 'UTF-8');
    $this->response->setJsonContent(['code' => '0']);
    return false;
  }

  public function jsonAction($param) {
    $this->response->setContentType('application/json', 'UTF-8');
    $this->response->setJsonContent($param);
    return false;
  }
}

/api/machine not work

/api/notfound is ok

I try to read https://docs.phalconphp.com/zh/3.3/api/Phalcon_Http_Response

but nothing to help me

You should use the dispatcher to forward to other actions

  public function machineAction() {
    $this->dispatcher->forward([
        'action' => 'json',
        'params' => ['code'=>0],
    ]);
  }


40.3k

You need to return your response:

  return $this->jsonAction(['code' => '0']);


503
edited Jul '18

[code] public function jsonAction($param) { $this->response->setContentType('application/json', 'UTF-8'); $this->response->setJsonContent($param); $this->response->setStatusCode(200, "OK"); return $this->response->send(); }

[/code]