【发布时间】:2017-12-20 20:24:50
【问题描述】:
我有一个可以进行搜索的 codeigniter 函数,它工作正常,但是当我在单个页面上进行新搜索时出现问题,在单击搜索按钮时,单个页面的相同 url 在 url 栏上重复,因此采取我到一个错误的链接。在下面的 sn-ps 中查看它的行为;
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
这里是函数;
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;
}
这个在另一个页面中显示搜索结果:
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);
}
终于到了所有魔法发生的地方;
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);
}
【问题讨论】:
标签: php codeigniter url