CodeIgniter Forums
Validation in controller for "patch" request - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Validation in controller for "patch" request (/showthread.php?tid=79929)



Validation in controller for "patch" request - Taras - 08-18-2021

Hello!
I want to add "update" action to controller as patch.
I've created this test:
PHP Code:
$attributes = ['title' => 'Changed Title'];
$response $this->patch(route_to('project.update'1), $attributes); 

Now the only method to retrieve data in controller is:
PHP Code:
$this->request->getVar(['title']); 

I.e. data are not in POST array. This is ok until I try to run validation:
PHP Code:
$this->validate(['title' => 'required|min_length[3]|max_length[128]']);
$e $this->validator->getErrors(); 

Now $e has message that "The title field is required". I.e. validation does not see passed data.
When I change action type to post it works as expected.
Is there any way to implement validation for patch or I have to use post? What are correct tests if patch can be used?


RE: Validation in controller for "patch" request - Taras - 08-19-2021

Ok, I've found solution. I have to run validation manually supplying data gathered with getVar.

PUT does this automatically though. But it that case I have some troubles in creating test request with $this->put() as passing data in array doesn't work. It would be nice to have all these methods to work in a same way.