how to load view into another view codeigniter 2.1?

孤人 提交于 2019-11-27 06:34:24

Two ways of doing this:

  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);
    
  2. 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';
    

Create a helper function

function loadView($view,$data = null){
    $CI = get_instance();
    return $CI->load->view($view,$data);
}

Load the helper in the controller, then use the function in your view to load another one.

<?php 
...
    echo loadView('secondView',$data); // $data array
...
?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!