[英]how to load view in codeigniter with variable?
hi i want to just load the view page using variable not by direct name 嗨,我只想使用变量而不是直接名称来加载视图页面
here is my code:- 这是我的代码:-
function load_views()
{
$this->load->model('test_model');
$data=$this->test_model->getMenu();
foreach($data as $data_menu) {
echo $data_menu->views;
$this->load->view($data_menu->views);
}
}
output : 输出:
test_view
An Error Was Encountered Unable to load the requested file: .php
actually it takes the value from db but it did not call the view file which is present in the view folder. 实际上,它从db获取值,但没有调用view文件夹中存在的view文件。
this is my view page : 这是我的查看页面:
<div class="panel-heading">
<h3 class="panel-title">Dashboard</h3>
</div>
<br/>
<div class="row">
<?php
$count = 0;
foreach($m as $data_menu){
if(($count% 4== 0))
{
?>
<div class = "row"></div>
<?php
}
?>
<div class="col-md-3">
<!--<a href="<?/*php echo base_url()*/?>index.php/<?php/* echo $data_menu->views*/?>">-->
<a href="<?php echo base_url()?>index.php/dn_login_controller/load_views">
<img class="img-rounded" src="" height="80" width="80" />
<div class="caption">
<h3><?php echo $data_menu->function_name; ?></h3>
</div>
</a>
</div>
<?php
$count++;
}
?>
</div>
</div>
Now in the view i want load views dynamically but i cant... please help me..... 现在在视图中,我想动态加载视图,但我不能...请帮助我.....
If you var_dump($data)
you will see that it has an empty value somewhere in the array. 如果您使用
var_dump($data)
,则将在数组中某处看到一个空值。
As kumar_v said in a comment, try to check for empty values 正如kumar_v在评论中所说,请尝试检查空值
foreach($data as $data_menu) {
if(!empty(trim($data_menu->views)))
$this->load->view($data_menu->views);
}
This issue might be because, you cannot just directly load multiple views from single function/controller, when you just load view CI will send it to browser. 这个问题可能是因为,您不能仅从单个功能/控制器直接加载多个视图,而仅在加载视图CI时会将其发送到浏览器。 There are two other workaround for this :
还有其他两种解决方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.