Welcome Guest, Not a member yet? Register   Sign In
Set a $_GET value
#1

(This post was last modified: 05-15-2024, 07:28 AM by CCAldo.)

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?
Reply
#2

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
Simple CI 4 project for beginners codeigniter-expenses
Reply
#3

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

(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.
Reply
#5

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
Simple CI 4 project for beginners codeigniter-expenses
Reply




Theme © iAndrew 2016 - Forum software by © MyBB