我建立了一个目录网站。目录位置位于http://localhost/bookstore/site/catalog
。然后,如果我点击其中一个,则网址会更改为http://localhost/bookstore/site/detail/100016
,并显示图书的详细信息。
现在我点击分页,将网址更改为http://localhost/bookstore/site/catalog/12
,其工作正常。但是如果我点击其中一本书,它就不会显示书的细节,因为网址会更改为http://localhost/bookstore/site/catalog/detail/100005
。
你能看到有什么不同吗?是的,网址仍保存方法catalog
,因此无法显示图书的细节。我该怎么办?
这是我的控制器
public function catalog()
{
$config['full_tag_open'] = '<div class="pagination pagination-colory"><ul>';
$config['full_tag_close'] = '</ul></div>';
$config['first_link'] = '« First';
$config['first_tag_open'] = '<li class="prev page">';
$config['first_tag_close'] = '</li>';
$config['last_link'] = 'Last »';
$config['last_tag_open'] = '<li class="next page">';
$config['last_tag_close'] = '</li>';
$config['next_link'] = 'Next →';
$config['next_tag_open'] = '<li class="next page">';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '← Previous';
$config['prev_tag_open'] = '<li class="prev page">';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page">';
$config['num_tag_close'] = '</li>';
$config['base_url'] = base_url('site/catalog');
$config['total_rows'] = $this->db->get('buku')->num_rows();
$config['per_page'] = 12;
//$config['uri_segment'] = 3;
$dari = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['databuku'] = $this->m_site->show_buku($config['per_page'],$dari);
$this->pagination->initialize($config);
$this->load->view('v_catalog_buku', $data);
}
模型
function show_buku($limit, $offset)
{
$this->db->order_by("id_buku", "desc");
$query = $this->db->get("buku", $limit, $offset);
return $query->result();
}
查看
<table>
<div class="row">
<?php foreach($databuku as $row ):?>
<a href="<?php base_url(); ?>detail/<?php echo $row->id_buku; ?>"><div class="span3" style="height:450px;" >
<div class="icons-box">
<div class="row" style="height:100px;">
<div class="body"><h3><?php echo $row->judul; ?></h3></div>
</div>
<div class="row" style="height:200px;">
<img src="<?php echo base_url('uploads/'.$row->img);?>" height="120px" width="120px"/>
</div>
<div class="row">
<div><h3>Rp.<?php echo number_format($row->harga,2,",",".");?></h3></div>
</div>
</div>
</div></a>
<?php endforeach; ?>
</div>
</table>
<div class="box-content" align="center">
<?php echo $this->pagination->create_links(); ?>
</div>
<!-- end: Row -->
</div>