带有数组的flashdata代码点火器

Kur*_*rro 2 php arrays codeigniter

我在flashdata codeigniter上的数组上有问题,无法发送警报,如果没有框架,此代码无法正确运行,我将其修改为codeigniter,但无法正常工作。

控制器代码:

    function reply(){
    $id = $this->input->post('id');

    $err = array();

    if(!$_POST['msg']) {
        $err[] = 'all the fields must be filled in!';
    }

    else if(!count($err)){
        $data = array(
            'DestinationNumber'=> $this->input->post('hp'),
            'TextDecoded'=> $this->input->post('msg'),
            'i_id'=> $this->input->post('id'));

        $this->inbox_model->reply($data);

        if($data >= 1) {
            $this->session->set_flashdata['msg']['success']='Send Success!';
        }

        else {
            $err[] = 'Send Failed!';
        }

    }

    if(count($err)){
        $this->session->set_flashdata['msg']['err'] = implode('<br />',$err);
    }

    redirect('sms/inbox/read/'.$id);
}
Run Code Online (Sandbox Code Playgroud)

查看代码:

if($this->session->flashdata['msg']['err']){
     echo "<div class='alert alert-danger alert-dismissible'>
           <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
           ".$this->session->flashdata['msg']['err']."</div>";
           $this->session->unset_flashdata['msg']['err'];
}                    
if($this->session->flashdata['msg']['success']){
     echo "<div class='alert alert-success alert-dismissible'>
           <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
           ".$this->session->flashdata['msg']['success']."</div>";
           $this->session->unset_flashdata['msg']['success'];
}
Run Code Online (Sandbox Code Playgroud)

谁能帮我?

Kha*_*ara 6

您可以使用简单的方法将数组设置为flashdata会话

$array_msg = array('first'=>'<p>msg 1</p>','second'=>'<p>msg2</p>');
Run Code Online (Sandbox Code Playgroud)

然后将其传递给会话

$this->session->set_flashdata('msg',$array_msg);
Run Code Online (Sandbox Code Playgroud)

然后访问它

$msg = $this->session->flashdata('msg');
echo $msg['first'];
Run Code Online (Sandbox Code Playgroud)