Udara Suranga
Udara Suranga

Reputation: 153

how to create search function in codeigniter

I want to create simple search function. I follow some example. but I was unable to get results. please help me.

//view page

<form class="navbar-form" role="search" action=" {{ base_url }}search/search_keyword" method = "post">
    <div class="input-group">
        <input type="text" class="form-control" placeholder="Search" name = "keyword"size="15px; ">
        <div class="input-group-btn">
            <button class="btn btn-default " type="submit" value = "Search"><i class="glyphicon glyphicon-search"></i></button>
        </div>
    </div>
</form>

//controller

function search_keyword()
{
    $keyword    =   $this->input->post('keyword');
    $data['results']    =   $this->mymodel->search($keyword);
    $this->twig->display('result_view.php',$this->data);
    //$this->load->view('result_view.php',$data);
}

}

//model

function search($keyword)
{
    $this->db->like('item_name',$keyword);
    $query  =   $this->db->get('bracelets');
    return $query->result();
}

Upvotes: 1

Views: 15663

Answers (2)

Saty
Saty

Reputation: 22532

Change

 $this->twig->display('result_view.php',$this->data);

TO

 $this->load->view('result_view.php',$data);

Upvotes: 2

Denish Makadia
Denish Makadia

Reputation: 81

Use This Function

function search_keyword()
{
    $keyword=$this->input->post('keyword');
    $data['results']=$this->mymodel->search($keyword);
    $this->twig->display('result_view.php',$data);
}

Upvotes: 1

Related Questions