dongmi4035 2011-11-29 11:09
浏览 33

set_flashdata有时无法在我的codeigniter应用程序中工作

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

  • 写回答

1条回答 默认 最新

  • dsj8086 2011-11-29 11:37
    关注

    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)

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大