We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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.phalcon.io/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],
    ]);
  }


51.1k

You need to return your response:

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


1.9k
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]