简体   繁体   中英

CodeIgniter is caching view variable even if I explicitly set it again

I'm using the CodeIgniter PHP framework. I have a simple form that has an $editcode hidden variable that gets sent on form submit. The form submits data to a form processing function which then redisplays the view with the form again, however with the $editcode$ variable changed to a new value.

The problem is that no matter what I do, the value of $editcode remains the same as the original value even after the form is submitted and the view redrawn with a new $editcode variable.

Extract from my view showing how $editcode is included and submitted.

echo form_open('/add', $formattributes);
echo form_hidden('editcode', set_value('editcode', $editcode));
echo form_submit('submit','Submit!','id="submit"');

The add() function code (the $refreshed_editcode is positively different from the original $editcode that got generated).

...
$data['editcode'] = $refreshed_editcode;
$this->load->view('includes/template', $data);

When the view gets redrawn by the add() function, the $editcode value should be $refreshed_editcode, but instead it's still the original value.

I know CodeIgniter does some caching of variables for nested views, however in this case I am explicitly resending new values for the $editcode variable. What gives?

Try getting rid of the call to set_value. Since the form field is hidden, it really shouldn't give you much benefit anyway, and I suspect that is where the "caching" is happening (If I'm not mistaken that function is part of the form_helpers file and it actually is designed to cache to help re-populate data, but it has been a while since I've used it).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM