简体   繁体   English

即使我再次明确设置CodeIgniter也在缓存视图变量

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

I'm using the CodeIgniter PHP framework. 我正在使用CodeIgniter PHP框架。 I have a simple form that has an $editcode hidden variable that gets sent on form submit. 我有一个具有$ editcode隐藏变量的简单表单,该变量在表单提交时发送。 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. 表单将数据提交到表单处理功能,然后再次使用该表单重新显示视图,但是$ editcode $变量更改为新值。

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. 问题是,无论我做什么,即使提交表单并使用新的$ editcode变量重新绘制视图后,$ editcode的值仍与原始值相同。

Extract from my view showing how $editcode is included and submitted. 从我的视图中摘录,显示了如何包括和提交$ editcode。

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). add()函数代码($ refreshed_editcode与生成的原始$ editcode有明显不同)。

...
$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. 当通过add()函数重绘视图时,$ editcode值为$ refreshed_editcode,但它仍然是原始值。

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. 我知道CodeIgniter会为嵌套视图进行一些变量缓存,但是在这种情况下,我将显式重新发送$ editcode变量的新值。 What gives? 是什么赋予了?

Try getting rid of the call to set_value. 尝试摆脱对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). 由于表单字段是隐藏的,因此无论如何它实际上都不会给您带来太大的好处,而且我怀疑这是“缓存”发生的地方(如果我没记错的话,该函数是form_helpers文件的一部分,它实际上是设计好的缓存以帮助重新填充数据,但是自从我使用它已经有一段时间了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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