Thanh Nguyen
Thanh Nguyen

Reputation: 5352

Searching in Codeigniter using URL?

Search form:

    <form action="<?php echo base_url()?>product/search" method="post">
        <input type="text" name="proname" />
        <button class="submit_btn" type="submit">TÌM KIẾM</button>
    </form>

My Controller:

function search(){
    $product_name = trim($this->input->post('proname'));
    $search = array('name' => $product_name);
    $param = $this->uri->assoc_to_uri($search);             
    if($product_name == '/'){
        redirect('product/search_result/'.$param);
    }else{
        redirect('product/search_result/'.$param);
    }
}

function search_result(){

    $result = $this->uri->segment_array();      
    $data['page_title'] = 'Result';     
    $data['pro'] = $this->data_mod->search_array('ebook',array('e_title_vn' => $result[4]));
    $data['keyword'] = $result[4];
    $this->load->view('search_result',$data);
}

When I echo the keyword (as $this->uri->segment(4)), example:

từ khóa

it will show

t%E1%BB%AB%20kh%C3%B3a

I don't know why, can anyone help me?

(I'm bad at English, so sorry. my language is Vietnamese.)

Upvotes: 1

Views: 514

Answers (1)

SubRed
SubRed

Reputation: 3187

$param that you add on your redirect URL will be encoded, you should use

urldecode($this->uri->segment(4));

to get it displayed right.

Upvotes: 1

Related Questions