Load view from helper Codeigniter?

codeigniter, php

Solution

Yes, you can. Create your helper, say `views_helper.php`:

if(!function_exists('view_loader')){

  function view_loader($view, $vars=array(), $output = false){
    $CI = &get_instance();
    return $CI->load->view($view, $vars, $output);
  }
}

`$view` is the view file name (as you would normally use), and `$vars` an array of variables you want to pass (as you would normally do), pass a `true` as optional third parameter to have it returned (as it would normally happen) as content instead of it just being loaded;

Just load your helper (or autoload it):

$this->load->helper('views');
$data = array('test' => 'test');
view_loader('myview', $data)

Problem

Can i load view from helper in codeigniter? I have been looking for a present, but it seems no one has discussed it.

Original source