codeigniter:将数据传递到视图中包含的视图 [英] codeigniter : pass data to a view included in a view
问题描述
我有一个控制器,并从一个函数包含两个视图,如下所示
$ this-> load-> view ('includes / header',$ data);
$ this-> load-> view('view_destinations',$ data);
视图文件 view_destinations.php
php菜单文件如下
< ;? $ this-> load-> view('includes / top_menu'); >
我的问题是,如何将从控制器获取的数据传递到 top_menu.php
?
谢谢你们
p>
$ data ['nestedView'] ['otherData'] ='testing';
$ b 你调用 $ this-> load-> view('view_destinations',$ data);
view_destinations
文件将具有
$ nestedView ['otherData'];
您可以在这一点上传入嵌套视图文件。
< ;? $ this-> load-> view('includes / top_menu',$ nestedView); >
在top_menu文件中,你应该有 $ otherData
包含testing。
I have a controller and including two views from one function as below
$this->load->view('includes/header',$data);
$this->load->view('view_destinations',$data);
The view file view_destinations.php
including a php menu file as follows
<? $this->load->view('includes/top_menu'); ?>
My question is, how can I pass data that is fetched from the controller to this included top_menu.php
?
Thank you guys
解决方案 Inside your controller, have
$data['nestedView']['otherData'] = 'testing';
before your view includes.
When you call
$this->load->view('view_destinations',$data);
the view_destinations
file is going to have
$nestedView['otherData'];
Which you can at that point, pass into the nested view file.
<? $this->load->view('includes/top_menu', $nestedView); ?>
And inside your top_menu file you should have $otherData
containing 'testing'.
这篇关于codeigniter:将数据传递到视图中包含的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!