CodeIgniter 正在缓存视图变量,即使我再次显式设置它
我正在使用 CodeIgniter PHP 框架。我有一个简单的表单,其中有一个 $editcode 隐藏变量,该变量在表单提交时发送。表单将数据提交到表单处理函数,然后该函数再次使用表单重新显示视图,但 $editcode$ 变量更改为新值。
问题是,无论我做什么,即使提交表单并使用新的 $editcode 变量重绘视图后, $editcode 的值仍与原始值相同。
我的视图摘录显示了如何包含和提交 $editcode。
echo form_open('/add', $formattributes);
echo form_hidden('editcode', set_value('editcode', $editcode));
echo form_submit('submit','Submit!','id="submit"');
add() 函数代码($refreshed_editcode 与生成的原始 $editcode 完全不同)。
...
$data['editcode'] = $refreshed_editcode;
$this->load->view('includes/template', $data);
当 add() 函数重绘视图时,$editcode 值应该为 $refreshed_editcode,但它仍然是原始值。
我知道 CodeIgniter 会对嵌套视图的变量进行一些缓存,但是在这种情况下,我显式地重新发送 $editcode 变量的新值。什么给?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试摆脱对 set_value 的调用。由于表单字段是隐藏的,无论如何它真的不应该给你带来太多好处,我怀疑这就是“缓存”发生的地方(如果我没有记错的话,该函数是 form_helpers 文件的一部分,并且它实际上是设计的缓存以帮助重新填充数据,但我已经有一段时间没有使用它了)。
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).