how to load view into another view codeigniter 2.1? how to load view into another view codeigniter 2.1? codeigniter codeigniter

how to load view into another view codeigniter 2.1?


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...?>