问题描述
我使用的是 CodeIgniter 2.1.0,我想在数据库中插入数据后收到类似您的信息已成功更新."的消息.对于这项工作,我在 CI_Controller 中有以下功能:
function myCiInser(){...这是我的查询...//$data: 这个var是true的结果查询如果($数据){$this ->会话 ->set_flashdata('message', '您的信息已成功更新.');重定向('网址/我的网址');}}
我认为:
session->flashdata('message');如果($消息){echo '
'.$消息.'</div>';}//我测试这个:echo $message;"但不要给出输出?>
但是我没有在视图中提供消息但是 redirect
已经完成并且工作正常.在表 ci_sessions
列 user_data
的数据库中,我有这个:
a:2:{s:9:"user_data";s:0:"";s:19:"flash:new:message";s:42:"你的信息已成功更新.";}
如何解决这个问题?
更新:
我有以下错误(我从 chorme 使用,并通过 Ctrl+Shift+j 我收到此警报):
加载资源失败:服务器响应状态为 404(未找到)
我修复了它(现在我没有错误)但在显示消息中仍然是同样的问题.我该怎么办?
来自 Codeigniter Session Class 文档,关于Flashdata,我们可以阅读:
CodeIgniter 支持flashdata",或者会话数据可用于下一个服务器请求,然后自动清除.
您的问题可能是当您重定向时,该过程需要多个请求,清除您的 flashdata.
要查看是否是这种情况,只需将以下代码添加到您要重定向到的控制器的构造函数中:
$this->session->keep_flashdata('message');
这将保留另一个服务器请求的 flashdata,以供以后使用.
I use CodeIgniter 2.1.0, i want after insert data in database get a message like "Your information was successfully updated.". For this work i have in CI_Controller following function:
function myCiInser(){
... Here is my query ...
//$data: this var is result query that is true
if($data){
$this -> session -> set_flashdata('message', 'Your information was successfully updated.');
redirect('url/myurl');
}
}
And i have in view as:
<?php
$message = $this->session->flashdata('message');
if($message){
echo '<div id="error_text">' . $message . '</div>';
}
//I test this : "echo $message;" but don't give output
?>
But i don't give message in view but redirect
is done and work true. and in database in table ci_sessions
column user_data
i have this:
How can fix this problem?
UPDATE:
I had the following error (i use from chorme and by Ctrl+Shift+j i get this alert):
And i fix it (Now i do not have the error) but still is same problem in display message. what do i do?
From the Codeigniter Session Class documentation, regarding Flashdata we can read:
Your problem might be that when you redirect, the process takes more than one request, clearing your flashdata.
To see if that's the case, just add the following code to the constructor of the controller you are redirecting to:
$this->session->keep_flashdata('message');
This will keep the flashdata for another server request, allowing it to be used afterwards.
这篇关于CodeIgniter “flashdata"不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!