2

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?

6
  • Why doesn't it work? What kind of error or output do you get? Please try to provide as much information as you can to be able to get better answers. Commented Oct 8, 2016 at 15:27
  • i have no error, another code works fine, only flashdata not shown Commented Oct 8, 2016 at 16:44
  • Did you check your webserver logs? Commented Oct 8, 2016 at 16:51
  • there nothing error on web server, i change config log CI to 1, and found this on log folder CI, ERROR - 2016-10-09 00:15:03 --> 404 Page Not Found: ../modules/sms/controllers//index ERROR - 2016-10-09 00:15:05 --> Severity: Notice --> Indirect modification of overloaded property CI_Session::$set_flashdata has no effect C:\xampp\htdocs\myaps\application\modules\sms\controllers\inbox.php 66 ERROR - 2016-10-09 00:15:05 --> 404 Page Not Found: ../modules/sms/controllers//index. and inbox.php 66 code is $this->session->set_flashdata['msg']['err'] = implode('<br />',$err); Commented Oct 8, 2016 at 17:24
  • Go to the codeigniter website and read the user guide relating to flashdata Or read the destructions in your local copy of the user_guide... When something dont work, go back and read up on it... To give you a hint, you are using it incorrectly. Commented Oct 9, 2016 at 0:39

2 Answers 2

8

you could set array to flashdata session using the simple way

$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'];
Sign up to request clarification or add additional context in comments.

1 Comment

haii, thanks for giving a hint, with a little modification the code works now, event not as perfect as i want, this is the code :
0

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>"; }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.