Php CodeIgniter:设置闪存数据不工作
我使用以下代码来管理搜索结果中的分页:Php CodeIgniter:设置闪存数据不工作,php,codeigniter,codeigniter-2,Php,Codeigniter,Codeigniter 2,我使用以下代码来管理搜索结果中的分页: if ($this->input->post('search-notes') && (is_string($this->input->post('search-notes')) || is_string($this->input->post('search-notes')))): $this->session->set_flashdata('search-notes', $_POST[
if ($this->input->post('search-notes') && (is_string($this->input->post('search-notes')) || is_string($this->input->post('search-notes')))):
$this->session->set_flashdata('search-notes', $_POST['search-notes']);
$post['search-notes'] = $this->input->post('search-notes');
elseif ($this->session->flashdata('search-notes')):
$this->session->set_flashdata('search-notes', $this->session->flashdata('search-notes'));
$post['search-notes'] = $this->session->flashdata('search-notes');
endif;
if (isset($post['search-notes']) && is_string($post['search-notes']) && !empty($post['search-notes'])):
...
所有这些都可以在我的开发计算机上正常工作,但在实时网站上却无法正常工作;最后的if()
语句的计算结果不是true
但是,如果我在最后一个if()
语句之前或之内回显$post['search-notes']
变量,它就会工作
这太奇怪了,我以前从未遇到过这样的事情
我正在使用CodeIgniter2.0
另一方面,最初的标题更为具体:“CodeIgniter中的
set\u flashdata()
函数存在问题”。但是由于一些易激动和过度的节制规则,我不得不把它淡化为一些没有意义的东西。你应该参加的第一件事是,一旦你调用$this->session->flashdata('search-notes')
方法,它就会取消会话中的'search-notes'
项
因此,当您第二次检查$this->session->flashdata('search-notes')
时,'search-notes'
将不再存在
如果要使项目保持会话状态,请使用和
此外,您还可以在第一次调用flashdata()
之前使用keep\u flashdata('search-notes')
设置\u flashdata()之后或flashdata()
之前,通过附加请求保留flashdata变量
作为旁点:无需检查
isset()
和!同时清空()empty()
,并返回FALSE
还有一个关于Netuts+的好方法,可能会很有用
JU作为演示:
不要复制,检查逻辑
if($\u POST['search-notes']和is_string($\u POST['search-notes']))
{
$post['search-notes']=$this->input->post('search-notes'/*,TRUE*/*启用XSS筛选*/);
$this->session->set_flashdata('search-notes',$post['search-notes');
}
elseif($searchNotes=$this->session->flashdata('search-notes'))
{
$post['search-notes']=$searchNotes;
}
如果(!empty($post['search-notes'])并且是字符串($post['search-notes']):
// ...
如果需要在会话中保留搜索注释
项,请在第一条If
语句中使用以下内容:
if($\u POST['search-notes']和is_string($\u POST['search-notes']))
{
$post['search-notes']=$this->input->post('search-notes'/*,TRUE*/*启用XSS筛选*/);
$this->session->set_flashdata('search-notes',$post['search-notes');
//通过附加请求保留flashdata
$this->session->keep_flashdata('search-notes');
} // ...
Hashem,谢谢你的努力,但这没什么区别。另外,由于$post['search-notes']未计算,最终if()语句中有一个错误。但是,正如我前面所说的,如果我重复这个变量,它会进行计算。你能写var_dump($post['search-notes'])吗在最后一个if
之后进行code>并发布结果?好的,我尝试了set_userdata()和userdata()函数,它们都正常工作。哈希姆,谢谢。