Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load view from helper Codeigniter?

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

like image 993
Khalifa Esha Avatar asked Jun 24 '26 20:06

Khalifa Esha


1 Answers

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)
like image 148
Damien Pirsy Avatar answered Jun 27 '26 09:06

Damien Pirsy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!