[英]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.