CodeIgniter Forums
Add a new function to add to request methods (POST, GET etc) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Add a new function to add to request methods (POST, GET etc) (/showthread.php?tid=82395)



Add a new function to add to request methods (POST, GET etc) - mrsyh - 07-06-2022

Hi,
I'm not sure if the functionality for this already exists as I haven't been able to find any documentation for this in the CI docs. Basically we should be able to add to a GET or POST request vars manually using a method like
PHP Code:
$this->request->setPost('key' => 'value'); 

Currently if you need to add something to a request inside a controller, then you set it like so
PHP Code:
$_POST['key'] = 'value'
And then if you try to use
PHP Code:
$this-request->getPost(); 
the newly added key - value pair doesn't appear in that method.


RE: Add a new function to add to request methods (POST, GET etc) - includebeer - 07-06-2022

It's not super clear in the doc, but what you're looking for is setGlobal:
PHP Code:
$this->request->setGlobal('post', [
    'foo' => 'bar',
    'bar' => 'baz',
]); 



RE: Add a new function to add to request methods (POST, GET etc) - mrsyh - 07-06-2022

(07-06-2022, 01:40 PM)includebeer Wrote: It's not super clear in the doc, but what you're looking for is setGlobal:
PHP Code:
$this->request->setGlobal('post', [
    'foo' => 'bar',
    'bar' => 'baz',
]); 
Yes I saw that, but that overwrites the values of all other $_POST variables.


RE: Add a new function to add to request methods (POST, GET etc) - kenjis - 07-06-2022

> Basically we should be able to add to a GET or POST request vars manually

Why do you need such a functionality?