loadComponent('FormProtection');` * * @return void */ public function initialize(): void { parent::initialize(); $this->loadComponent('Authentication.Authentication'); $this->logged_user = $this->Authentication->getIdentity(); $this->nopaginate = $this->request->getQuery('nopaginate') !== null && $this->request->getQuery('nopaginate'); } /** * respond * * @param Int $code * @param null|Object|Array|String $bodyResponse * @param String $content * @return Response */ public function respond(Int $code = 200, null|Object|Array|String $bodyResponse = null, String $content = "application/json") : Response { $bodyResponse = is_object($bodyResponse) || is_array($bodyResponse) ? $bodyResponse : ['result' => $bodyResponse]; $response = $this->getResponse(); $response = $response->withHeader('Access-Control-Allow-Origin', '*'); $response = $response->withHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE, PUT'); $response = $response->withHeader('Access-Control-Max-Age', '60'); $response = $response->withHeader('Access-Control-Allow-Headers', 'x-requested-with, Content-Type, origin, authorization, accept, client-security-token'); return $response->withStringBody(json_encode($bodyResponse))->withStatus($code)->withType($content); } }