Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

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

How can fix this problem?

UPDATE:

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
286 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...