如何将视图加载到另一个视图 codeigniter 2.1 中? [英] how to load view into another view codeigniter 2.1?

查看:20
本文介绍了如何将视图加载到另一个视图 codeigniter 2.1 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 CI,我在 CI 的网站上看到您可以将视图作为发送到主"视图的数据的可变部分加载,因此,根据站点(说了很多事情,很多不像他们说的那样......ej分页和其他人)我做了这样的事情

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?

推荐答案

两种方法:

  1. 提前加载(就像你在做的那样)并传递到另一个视图

  1. 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屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆