CodeIgniter Forums
Set a $_GET value - 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: Set a $_GET value (/showthread.php?tid=90868)



Set a $_GET value - CCAldo - 05-15-2024

PHP Code:
localhost?foo=bar
$_GET
['foo'] = 'baar'
echo 
$_GET['foo']; // 'baar'

localhost?foo=bar
$_GET
['foo'] = 'baar'
echo 
$this->request->getGet('foo'); // 'bar' 


I encountered a loop because I couldn't update the $_GET parameters during the same request.

PHP Code:
# Solution? 
$this->request->setGet('foo''bar');  
$this
->request->setPost('foo''bar');  

Is this possible?


RE: Set a $_GET value - ozornick - 05-15-2024

Why change the GET parameter in the process? It is better to manipulate the variable $foo = $_GET[foo]
That's right, Request knows nothing about the new Get, Post data because the object is created once when the page loads


RE: Set a $_GET value - kenjis - 05-15-2024

You should not change the $_GET or the GET parameter in the request.
Why do you need to change it?


RE: Set a $_GET value - CCAldo - 05-15-2024

(05-15-2024, 07:18 PM)kenjis Wrote: You should not change the $_GET or the GET parameter in the request.
Why do you need to change it?

Why, why not?
If it is possible in basic PHP then it seems to be a allowed way of working.

It's old code, but it works.
Now I need to use the basic, non-CI4-way, $_GET['foo'] to get the updated value.


The other possible solution would be redirect to the same URI with updated params, but that's seems to be a overkill.

Sure, It's better to to manipulate the variable $foo, but I thought the request could be updated with the new Get.


RE: Set a $_GET value - ozornick - 05-16-2024

If someone has done this before, it doesn't mean it's right. 
PHP does not remember data between updates. There is no reason to change GET. Use a different variable