How to validate an API REST? |
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?
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.
(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. |
Welcome Guest, Not a member yet? Register Sign In |