[英]flashdata codeigniter with array
I have problem with array on flashdata codeigniter to send alert, if without framework this code work correcly, I modified this to codeigniter, but it does not work. 我在flashdata codeigniter上的数组上有问题,无法发送警报,如果没有框架,此代码无法正确运行,我将其修改为codeigniter,但无法正常工作。
Controller Code: 控制器代码:
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);
}
View Code : 查看代码:
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'];
}
Who can help me? 谁能帮我?
you could set array to flashdata session using the simple way 您可以使用简单的方法将数组设置为flashdata会话
$array_msg = array('first'=>'<p>msg 1</p>','second'=>'<p>msg2</p>');
then pass it to session 然后将其传递给会话
$this->session->set_flashdata('msg',$array_msg);
then access it 然后访问它
$msg = $this->session->flashdata('msg');
echo $msg['first'];
Controller : 控制器:
$err = array();
if(!$_POST['msg']) {
$err['msg_err'] = '<strong>Oh snap!</strong> all the fields must be filled in';}
View : 查看:
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>"; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.