简体   繁体   中英

How Can I get the Data and Flashmessage in Form by redirecting to a function in Codeigniter?

I want to display the success message and the Product size in Product page.. this is possible if pass the data in view, but not displaying by redirecting the function... here is my controller code

class Addcontroller extends MY_Controller{
function __construct() {
    parent::__construct();
      $this->load->model('vendor/Addmodel', 'add', TRUE);
      $this->load->model('vendor/Showmodel', 'show', TRUE);
}


  function add_product(){

   if($this->add->add_product($post)==TRUE){

        $this->db->close();
        $this->session->set_flashdata('success','Product has been added 
       successfully');
        return redirect('product');


    }
    function product(){

    $data['product_size'] = $this->show->show_product_size();
    $this->load->view('product',$data);

      }

     }
  }

add this to your constructor method:

$this->load->library('session');

set flashdata in the controller method:

$this->session->set_flashdata('item', 'value');

Retrieve in your view:

if(!empty($this->session->flashdata('item'))){
$flash=$this->session->flashdata('item');
//do whatever you want.
}

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM