Reputation: 119
I am having a codeigniter function that does searching which is working fine but the issues arises when I am making a new search on a single page whereby on clicking search button the same url of the single page duplicates on the url bar thus taking me to a wrong link. see how it behaves in the below snippets;
http://localhost/newsapp/bulletins/view/31
http://localhost/newsapp/bulletins/view/view/31
http://localhost/newsapp/bulletins/view/view/view/31 http://localhost/newsapp/bulletins/view/view/view/view/31
here are the functionss;
public function livesearch() {
$keyword = $this->input->post('keyword');
$query = $this->news_model->get_live_items($keyword);
foreach ($query as $row):
echo "<li><a href='view/$row->id'>" . $row->title . "</a></li>";
endforeach;
}
This one displays the search results in a another page:
public function search_keyword()
{
$keyword = $this->input->post('keyword');
$data['results'] =$this->news_model->get_live_items($keyword);
$data["top_news"] = $this->news_model->topnews();
$data["latest_news"] = $this->news_model->latestnews();
$this->load->view('result_view',$data);
}
finally this where all the magics are happening;
function view($id)
{
$data['news'] = $this->news_model->get_one_news($id);
$data["top_news"] = $this->news_model->topnews();
$data["latest_news"] = $this->news_model->latestnews();
$data['content'] = 'single'; // template part
$this->load->view('includes/template',$data);
}
Upvotes: 2
Views: 79
Reputation: 873
Your livesearch method should be
public function livesearch() {
$keyword = $this->input->post('keyword');
$query = $this->news_model->get_live_items($keyword);
foreach ($query as $row):
echo "<li><a href='" . base_url('bulletins/view/' . $row->id) . "'>" . $row->title . "</a></li>";
endforeach;
}
Upvotes: 0
Reputation: 2982
Try giving a full link like this
echo "<li><a href='".base_url()."view/$row->id'>" . $row->title . "</a></li>";
You are just including the view/$row->id
so it is adding the url rather than generating the required url.
Upvotes: 1