这确实是主观的,取决于您要如何处理URI。但是对于一个简单的选项,控制器看起来像这样
class Categories extends CI_Controller {
public function __construct() {
// this makes working with urls easier
$this->load->helper('url');
}
public function index() {
$this->load->model('Model_Category');
$data['row2']= $this->Model_Category->get_category();
$this->load->view('view_page.php',$data);
}
// Below,handle the logic for displaying a single category
public function details($slug) {
$this->load->model('Model_Category');
$data['row2']= $this->Model_Category->get_category_by_slug($slug);
$this->load->view('view_details_page.php',$data);
}
}
在您看来,像这样定义href:
我在此代码段中使用了子弹,但是您可以使用任何可以唯一标识数据库中类别行的东西。
<div class="row mb-4">
<div class="items mr-2 ml-2">
<?php foreach ($row2->result() as $key => $data) : ?>
<a class="text-light listcategory" href="<?= site_url('category/details/'.$data->slug) ?>">
<span><?= $data->name_cat ?></span>
</a>
<?php endforeach; ?>
/div>
</div>
最后,在模型中,查询单个类别行
public function get_category_by_slug($slug) {
$this->db->select('column1,column2,column3');
$this->db->from('categories_table');
$this->db->where('unique_column',$sulg);
return $this->db->get()->result();
}
本文链接:https://www.f2er.com/3132895.html