我现在正在学习php codigniter框架。
我正在制作博客系统。
我已经完成了博客登陆页面,这是1页上的5个博客,我现在正试图点击任何一个博客,它将进入相应的博客详细页面。
我应该如何向相应的博客提供详细页面链接。
这是我的控制器
Class News extends CI_Controller {
public function Index(){
$this->load->model("Newsmodel");
$data['a'] = $this->Newsmodel->select();
$this->load->view("news/news-landing",$data);
}
public function news_detail(){
$this->load->model("Newsmodel");
$data['a'] = $this->Newsmodel->select_single_row();
$this->load->view("news/news-detail",$data);
}
}
这是我对着陆页的看法
foreach ($a->result() as $single_result) {
echo "<div class='blog-post'>";
echo "<img src=".$single_result->image_path." alt='image is here'>";
echo "<div class='post-content-text'>";
echo "<h2><a href='".base_url('news/'.$single_result->id)."'>".$single_result->title."</a></h2>";
echo "<span>".$single_result->date."</span>";
echo "<p>".substr( $single_result->body, 0, 300 )."</p>";
echo "<a href='".base_url('news/'.$single_result->id)."'>Continue reading...</a>";
echo "</div>";
echo "</div>";
}
请提前帮助和谢谢。
答案 0 :(得分:1)
您必须将id
传递给news_detail
函数:
public function news_detail($id){
$data['a'] = $this->db->get_where('mytable', array('id' => $id))->row_array();
$this->load->view("news/news-detail",$data);
}
您需要将视图更改为仅continue reading link
:
echo "<a href='".base_url('news/news_detail/'.$single_result->id)."'>Continue reading...</a>";
答案 1 :(得分:0)
I replace this lines
$data['a'] = $this->Newsmodel->get_where('mytable', array('id' => $id))->row_array();
Into
$this->db->select('*');
$this->db->from('news');
$this->db->where('id', $id);
$data['a'] = $this->db->get();
Its Working, Thanks Yash.