Kurro Kurro - 1 month ago 16
PHP Question

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.

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'>&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'];
}


Who can help me?

Answer

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'>&times;</button>
".$this->session->flashdata('err')['msg_err']."</div>"; }