我有一个codeigniter功能,可以进行正常搜索,但是当我在单个页面上进行新搜索时会出现问题,在点击搜索按钮时,单页的相同网址会在网址栏上重复显示我错了。看看它在下面的片段中的表现;
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);
}
答案 0 :(得分:1)
尝试提供像这样的完整链接
view/$row->id
您只是包含private static ObjectArrayList<ObjectArrayList<IntArrayList>> getOddVertexCombinations(IntArrayList oddVertices,
ObjectArrayList<IntArrayList> buffer){
ObjectArrayList<ObjectArrayList<IntArrayList>> toReturn = new ObjectArrayList<>();
if (oddVertices.isEmpty()) {
toReturn.add(buffer.clone());
} else {
int first = oddVertices.removeInt(0);
for (int c = 0; c < oddVertices.size(); c++) {
int second = oddVertices.removeInt(c);
buffer.add(new IntArrayList(new int[]{first, second}));
toReturn.addAll(getOddVertexCombinations(oddVertices, buffer));
buffer.pop();
oddVertices.add(c, second);
}
oddVertices.add(0, first);
}
return toReturn;
}
,因此它会添加网址,而不是生成所需的网址。
答案 1 :(得分:1)
您的livesearch方法应该是
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;
}