我想製作一個基於角色的菜單列表,但是當我想將它們顯示到我的家庭視圖時,它不顯示列表..我該如何解決它?問題在於菜單列表未顯示分隔文件。 控制器我的數組有什麼問題?
public function getModules($id_module){
if($this->session->userdata('log')){
$data = $this->session->userdata('log');
$menu = array();
$seccions = $this->module->get_rows();
foreach ($seccions as $index => $seccion){
$modules = $this->module->query("SELECT CONCAT('".$seccion['id']."',storelte_modulo.id) AS id,CONCAT('".base_url('assets/img/sidebar')."','/',storelte_modulo.icon) as icon, storelte_modulo.modulo AS value,storelte_modulo.seccion_id,CONCAT('".base_url()."',storelte_modulo.url) AS url FROM storelte_modulo INNER JOIN storelte_modulo_perfil ON storelte_modulo_perfil.modulo_id = storelte_modulo.id WHERE seccion_id = $seccion[id] AND storelte_modulo_perfil.perfiles_id = $data[id] AND storelte_modulo_perfil.STATUS = 1");
$seccions[$index]['data']= $modules;
if (!count($seccions[$index]['data']))
unset($seccions[$index]);
}
foreach ($seccions as $item)
array_push($menu,$item);
$this->data['fields'] = $menu;
$this->load->view('modules_view',$this->data);
}
}
模型
public function get_rows(){
$this->db->select('id,seccion');
$this->db->from('storelte_seccion');
return $this->db->get()->result_array();
}
public function query($query){
return $this->db->query($query)->result_array();
}
視圖
home.php
<section class="content">
<!-- Small boxes (Stat box) -->
<div class="row">
<h3 class="text-center">Welcome to storeLTE, click a module below to get started!</h3>
<div class="home_module_list">
<div class="module_item">
<?php $this->load->view('modules_view'); ?>
</div>
</div>
</div>
<!-- Main row -->
<div class="row">
<!-- Left col -->
<section class="col-lg-12 connectedSortable">
</section>
</div>
</section>
模塊
<?php $this->load->view('header'); ?>
<div class="module_item">
<?php foreach ($fields as $session) : ?>
<?php foreach ($session['data'] as $itemData) : ?>
<div class="module_item" title="<?= $itemData['value'] ?>">
<a href="<?= $itemData['url'] ?>"><img src="<?= $itemData['icon'] ?>"/></a>
<a href="<?= $itemData['url'] ?>"><?= $itemData['value']?></a>
</div>
<?php endforeach ?>
<?php endforeach ?>
</div>
嘗試打印你在你的'menu'變量 – Zeeshan
沒有得到被顯示的還是它顯示空的div?您的環境是否已設置爲使用速記PHP? – RST