简体   繁体   English

如何通过重定向到Codeigniter中的函数来获取Form中的数据和Flashmessage?

[英]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: 在控制器方法中设置flashdata:

$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. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在CodeIgniter中,如何在重定向页面后清除“表单数据” - In CodeIgniter, how to clear “form data” after redirecting page Codeigniter如何获取config / form_validation.php数据? - codeigniter how can I get access to config/form_validation.php data? 为什么我无法在CodeIgniter中获取相同功能的数据 - Why can't I get data on same function in CodeIgniter 如何在PHP Codeigniter表单中获得一个下拉按钮? - How can i get a dropdown button in my PHP Codeigniter form? 如何在Codeigniter表单验证中获取字段数组的索引? - How can I get the index of a field array in codeigniter form validation? 如何在此 Codeigniter 3 应用程序中保留无效的编辑表单数据? - How can I persist invalid edit form data in this Codeigniter 3 application? 如何从Mysql和Codeigniter中的两个表中获取数据 - How can I get data from two tables in Mysql and Codeigniter 如何在Codeigniter中的到期日之间获取数据? - How can I get data between due date in Codeigniter? Codeigniter表单不更新也不重定向 - Codeigniter Form Not Updating And Not Redirecting 如何通过Codeigniter中的URL向控制器发送数据表单视图以及如何在控制器中获取数据 - How to send Data form view to controller through URL in codeigniter and how i get data in controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM