从辅助程序Codeigniter加载视图

从辅助程序Codeigniter加载视图

本文介绍了从辅助程序Codeigniter加载视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从codeigniter中的助手加载视图吗?我一直在寻找一个礼物,但似乎没有人讨论过。

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

推荐答案

是的,你可以。创建助手,说 views_helper.php

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 是视图文件名(通常使用的), $ vars 你想传递的变量数组a true 作为可选的第三个参数,使其返回(因为它通常会发生)作为内容,而不是只是加载;

$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)

这篇关于从辅助程序Codeigniter加载视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 17:22