![]() |
How to validate an API REST? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: How to validate an API REST? (/showthread.php?tid=76161) |
How to validate an API REST? - MatheusCastro - 04-17-2020 Hello, I'm extending Resource Controller In situations that are passed as GET I can validate this way: PHP Code: public function index() However, when it is necessary to pass the parameter through the function, how to solve this? PHP Code: public function show($id = null) Can anyone help? RE: How to validate an API REST? - jreklund - 04-17-2020 There are a hidden function named setGlobal (hidden as it's not in the documentation yet). That allow you to set get, post etc. PHP Code: public function show($id = null) Haven't tested it out myself. RE: How to validate an API REST? - MatheusCastro - 04-17-2020 (04-17-2020, 12:59 PM)jreklund Wrote: There are a hidden function named setGlobal (hidden as it's not in the documentation yet). That allow you to set get, post etc. Hello, interesting function. I ran some tests with it separately and I think I found some bugs. Try using: PHP Code: $this->request->setGlobal('post', ['id' => $id]); When using getVar, the declaration is not recognized. However, if you use getPost or getGet, the parameter will be recognized. PHP Code: $this->request->setGlobal('post', ['id' => $id]); And the $this->validate function within it has the withRequest that the request is getVar() PHP Code: public function withRequest(RequestInterface $request): ValidationInterface Solved using: PHP Code: public function show($id = null) Since withRequest identifies only the getVar that receives $ _REQUEST, I created the variable of this type. However, an issue addressed in the post above is still open. |