我在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);
}
查看代码:
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'>×</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'>×</button>
".$this->session->flashdata['msg']['success']."</div>";
$this->session->unset_flashdata['msg']['success'];
}
谁能帮帮我?
答案 0 :(得分:4)
您可以使用简单的方法将数组设置为flashdata会话
$array_msg = array('first'=>'<p>msg 1</p>','second'=>'<p>msg2</p>');
然后将其传递给会话
$this->session->set_flashdata('msg',$array_msg);
然后访问它
$msg = $this->session->flashdata('msg');
echo $msg['first'];
答案 1 :(得分:0)
控制器:
$err = array();
if(!$_POST['msg']) {
$err['msg_err'] = '<strong>Oh snap!</strong> all the fields must be filled in';}
查看:
if($this->session->flashdata('err')){
echo "<div class='alert alert-danger alert-dismissible'>
<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>
".$this->session->flashdata('err')['msg_err']."</div>"; }