I am using codeigniter , in my controller i can not set the flashdata , but i can set the user data
/**
* this will send the requests for the gmail wrapper
* @return void
* @author Sandaruwan
* */
function send_contacts()
{
$contacts = $this->input->post('contact');
if (count($contacts) != 0 && is_array($contacts))
{
$data = $this->gmailmanager->send_messeges($contacts);
echo "error message ===>"; print_r($this->message->get_message ()); echo "<br/>";
$this->session->set_flashdata('message',$this->message->get_message ());
echo "flash data ===>"; print_r($this->session->flashdata('message')); echo "<br/>";
$this->session->set_userdata('user',$this->message->get_message ());
echo "user data ===>"; print_r($this->session->userdata('user')); echo "<br/>";
exit;
redirect('connections/connection_inviter/invite');
}
else
{
$this->message->set_information(array(_('You have not selected a conatact!')));
$this->session->set_flashdata('message',$this->message->get_message ());
redirect('connections/connection_inviter/invite');
}
}
this is the result
error message ===>
Warning
Email sending error!
flash data ===>
user data ===>
Warning
Email sending error
!
the problem is i can get the error message
and userdata
but can not get the flashdata
, i can not figure out why i can not get the flashdata
right after initialized .
in some controllers flashdata works perfectly .
UPDATE
function invite() {
$this->load->library("connections/Outlookmanager");
print_r($this->ci->session->flashdata('message'); die;
//Invite friends links
$this->data['is_windows']=$this->outlookmanager->is_windows_user();
$this->load->view('connections/invite_friends', $this->data);
}
when i print flashdata
in function invite()
it is not printing .
UPDATE
hmmmm . actually there is a very interesting issue ,
i had the error message Email sending error
i changed it to err
now flash data working . i again changed message to Email sending error
and it is again not working . then i again changed it to err
then again flashdata works .
what is this , i think error message length is causing the problem here , and i don't know why
That's because flashdatas are (though CI uses the word "session"), actually, cookies, and therefore they're available only at the next request.
To be honest, I don't see the reason of setting and calling flashdatas right after their creation, why don't just print out the error instead and skip this useless step?
If you still want both, just do
$this->session->set_flashdata('message',$this->message->get_message());
echo $this->message->get_message();
So that you have a message now, and a message on whatever request you make later on
UPDATE:
Try calling the method of the $this
instance instead of $this->ci
print_r($this->session->flashdata('message');
I think I already saw you doing like this, using sometimes the reference to $this
and sometimes to another object, and IIRC I even answered a question about the difference. Why that? Why you use $this
in a location and then $this->ci->
in another? It might not make difference, but at least for the sake of consistency stick to one way (and I suggest using the "regular" one)