CodeIgniter“flashdata”不工作 [英] CodeIgniter "flashdata" doesn't work

查看:150
本文介绍了CodeIgniter“flashdata”不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CodeIgniter 2.1.0,我想在数据库中插入数据后得到一条消息,像您的信息已成功更新。对于这项工作我在CI_Controller下面的功能:

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
?>

但是我不在视图中给出消息,但 redirect 是完成和工作真实。在数据库中的 ci_sessions user_data 我有这样:

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:


a:2:{s:9:user_data; s:0:; s:19:flash:new:message; s:42:Your
信息已成功更新。;}

a:2:{s:9:"user_data";s:0:"";s:19:"flash:new:message";s:42:"Your information was successfully updated.";}

如何解决此问题?

UPDATE:

我遇到以下错误(我使用chorme和Ctrl + Shift +

I had the following error (i use from chorme and by Ctrl+Shift+j i get this alert):


无法加载资源:服务器响应状态为404
(找不到)

Failed to load resource: the server responded with a status of 404 (Not Found)

我修复它(现在我没有错误),但仍然是相同的问题在显示消息。我要做什么?

And i fix it (Now i do not have the error) but still is same problem in display message. what do i do?

推荐答案

从Codeigniter 会话类文档,关于 Flashdata ,我们可以阅读:

From the Codeigniter Session Class documentation, regarding Flashdata we can read:


CodeIgniter支持flashdata或会话数据,只有
可用于下一个服务器请求,然后自动
清除。

CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared.

您的问题可能是,当您重定向,该过程需要多个请求,清除您的flashdata。

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');

这将保存另一个服务器请求的flashdata,以便以后使用。

This will keep the flashdata for another server request, allowing it to be used afterwards.

这篇关于CodeIgniter“flashdata”不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆