Reputation: 153
I have two functions which use post method. they are working perfectly. but the problem is I can't use both of the at same time. how can I fix this problem.
function search_keyword()
{
$keyword = $this->input->post('keyword');
$this->data['result'] = $this->mymodel->search($keyword);
$this->twig->display('home.html', $this->data);
}
function genarate_csv(){
$pro_id = $this->input->post('keyword');
$this->data['re'] = $this->csv->ExportCSV($pro_id);
}
Upvotes: 0
Views: 251
Reputation: 153
buhaaaaa haaaa.... I fixed my problem. I use sessions to solve my problem. I think this will help noobs like me..
function __construct()
{
parent::__construct();
$this->load->model('mymodel');
$this->load->model('csv');
session_start();
$this->load->library('session');
}
public function search_keyword($key = "")
{
$keyword = $this->input->post('keyword');
$this->data['result'] = $this->mymodel->search($keyword);
$_SESSION[$key] = $keyword;
$this->twig->display('home.html', $this->data);
}
public function download($key = ""){
//print_r($_SESSION[$key]);
$keyword = $_SESSION[$key] ;
//print_r($keyword);
$this->data = $this->csv->ExportCSV($keyword);
$this->session->unset_userdata($keyword);
//$this->twig->display('home.html', $this->data);
}
Upvotes: 0
Reputation: 11987
try this
function search_keyword()
{
$keyword = $this->input->post('keyword');
$this->data['result'] = $this->mymodel->search($keyword);
$this->data['re'] = $this->csv->ExportCSV($keyword);
$this->twig->display('home.html', $this->data);
}
You can do it in same function
Upvotes: 0
Reputation: 3170
You can try this way
function search_keyword()
{
$keyword = $this->input->post('keyword');
$this->data['result'] = $this->mymodel->search($keyword);
$this->data['re'] = $this->genarate_csv($keyword);
$this->twig->display('home.html', $this->data);
}
function genarate_csv($keyword){
$re = $this->csv->ExportCSV($keyword);
return $re
}
Upvotes: 1