如何加载视图到另一个视图codeigniter 2.1? [英] how to load view into another view codeigniter 2.1?
问题描述
我一直在CI工作,我在CI的网站上看到,你可以加载一个视图作为您发送到主视图的数据的一个可变部分,所以,根据网站(说了很多事情,很多人不喜欢他们说... ej pagination和其他)我做了这样的事情
Ive been working with CI and I saw on the website of CI you can load a view as a variable part of the data you send to the "main" view, so, according the site (that says a lot of things, and many are not like they say ...ej pagination and others) i did something like this
$data['menu'] = $this->load->view('menu');
$this->load->view ('home',data);
这样做的结果是我得到了网站顶部菜单的回声开始我的身体和所有)和哪里应该是它的什么,如果在所有之前打印...我不知道老实说这个问题,以前有人有同样的问题吗?
the result of this is that I get an echo of the menu in the top of the site (before starts my body and all) and where should be its nothing, like if were printed before everything... I have no idea honestly of this problem, did anybody had the same problem before?
推荐答案
这样做的两种方法:
-
就像你在做),并传递到其他视图
Load it in advance (like you're doing) and pass to the other view
<?php
// the "TRUE" argument tells it to return the content, rather than display it immediately
$data['menu'] = $this->load->view('menu', NULL, TRUE);
$this->load->view ('home', $data);
从视图中加载视图:
Load a view "from within" a view:
<?php
// put this in the controller
$this->load->view('home');
// put this in /application/views/home.php
$this->view('menu');
echo 'Other home content';
这篇关于如何加载视图到另一个视图codeigniter 2.1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!