Udara Suranga
Udara Suranga

Reputation: 153

how to use post method in two functions in codeigniter

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

Answers (3)

Udara Suranga
Udara Suranga

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

Niranjan N Raju
Niranjan N Raju

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

Suvash sarker
Suvash sarker

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

Related Questions