这里我想基于我的数据库创建面包屑。这是我的数据库请看看
resource_category_id category_name parent_category
1 Tools 0
2 product literature 0
3 Terms and Conitions 0
4 crane library 1
5 geniune 1
6 lift planning 1
8 cranimax 6
我的控制器看起来像这样
$data['breadcrumbs'] = $this->Manito_model->get_breadcrumbs_details($resource_id);
这是我的模特
public function get_breadcrumbs_details($resource_id)
{
$query=$this->db->query("SELECT * FROM resource_category as c1 WHERE c1.resource_category_id = $resource_id UNION SELECT * FROM resource_category as c2 where c2.resource_category_id = 6 ");
return $query->result();
}
以下是我的观点,请看一下
<nav aria-label="breadcrumb" role="navigation">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="<?php echo base_url();?>home">Home Page</a></li>
<li class="breadcrumb-item"><a href="#">Resource</a></li>
<?php $breadcrumb = array_reverse($breadcrumbs);
if($breadcrumb){
foreach($breadcrumb as $bread){
?>
<li class="breadcrumb-item active" aria-current="page"><?php echo $bread->category_name;?></li>
<?php }}?>
这是我的$resource_id=8
,所以我假设我的结果与此tools/lift planning/cranimax.
现在我得到了像lift planning/cranimax
这样的结果。但是如果它包含多个多个子元素,我们怎么能得到面包屑呢