how can I fix it the values from fields because when I write in url http://localhost/storeLTE/login/getmodules/1 everything works well, but when I want to pass them through my home with <?php $this->load->view('modules_view'); ?>
<?php $this->load->view('modules_view'); ?>
it isnt work as separate files. how can I fix it?
controller
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);
}
}
view
<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>
view_modules
<?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>
Try changing the following line:
<?php $this->load->view('modules_view'); ?>
to:
<?php $this->load->view('modules_view', ['fields' => $fields]); ?>
This should give modules_view.php access to your $fields
variable from the controller. Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.