Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CodeIgniter:设置闪存数据不工作_Php_Codeigniter_Codeigniter 2 - Fatal编程技术网

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()函数,它们都正常工作。哈希姆,谢谢。