How to display error messages in CodeIgniter

In my controller, I put this code to check if the recycle bin is empty:

if (!$this->cart->contents()){
    $this->session->set_flashdata('message', 'Your cart is empty!');
}

$this->data['message'] = $this->session->flashdata('message');

$this->load->view('templates/header', $this->data);
$this->load->view('bookings', $this->data);
$this->load->view('templates/footer');

In my reservation view, I set this code to display a message:

<div id="infoMessage"><?php echo $message;?></div>

But on the first page, load the message "Your basket is empty!" not displayed. However, it will be displayed when I press the F5 key or refresh the browser.

I already read a codeigniter manual that says: "CodeIgniter supports flashdata or session data that will only be available for the next server request and then automatically cleared."

However, I do not know where to install this message so that it is available on the "next requrest server".

+5
source share
1

flashdata.

, , , flashdata . . .

:

  • . ( .)
  • flashdata .

( - , flashdata , , , ...):

:

if (!$this->cart->contents())
{
    $this->data['message'] = 'Your cart is empty!';
}

$this->load->view('templates/header', $this->data);
$this->load->view('bookings', $this->data);
$this->load->view('templates/footer');

:

<div id="infoMessage"><?php echo $message;?></div>

flashdata​​h2 >

, flashdata, :

:

if (!$this->cart->contents())
{
    $this->session->set_flashdata('message', 'Your cart is empty!');
}

redirect('/your_page');

:

 <div id="infoMessage"><?php echo $this->session->flashdata('message');?></div>

, - - , , , redirect('/your_page');, URL $this->load->helper('url');. HTTP-, PHP header. .


$this->session->keep_flashdata('message'); .

, , : $this->load->library('session'); ( , , .)

, , , , flashdata, , , , .

, , , ​​ .

+18

All Articles