CodeIgniter加载带有数据参数的文件 [英] CodeIgniter Load File with data parameter
本文介绍了CodeIgniter加载带有数据参数的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在CodeIgniter中有任何选项加载参数的文件,例如视图?
Is there any option in CodeIgniter to load files with parameters like in views?
在我的控制器中我加载这个文件: p>
In my Controller I load this File:
$path_to_logic = "extended_core/plugins/saphir_e-cms/be_extensions/$this->modul_id/package/logic.php";
$logic = $this->CI->load->file($path_to_logic, true);
我有一个 array()
控制器,我将传递到加载的文件,如 $ data
var在视图中。
I have an array()
in the controller that I would pass to the loaded file, like the $data
var in the views.
推荐答案
您需要将此功能添加到 Loader
类中。
You need to add this functionality into the Loader
class.
在 application / core /
文件夹中创建一个名为 MY_Loader.php
的新文件,如下所示:
In order to do that, create a new file named MY_Loader.php
inside the application/core/
folder, as follows:
/**
* My Custom Loader
*/
class MY_Loader extends CI_Loader
{
function __construct()
{
parent::__construct();
}
/**
* Custom File loader method
*
* @param string $path
* @param array $vars
* @param bool $return
* @return void
*/
public function file($path, $vars = array(), $return = FALSE)
{
return $this->_ci_load(array(
'_ci_path' => $path,
'_ci_vars' => $this->_ci_object_to_array($vars),
'_ci_return' => $return
));
}
}
然后使用以下值加载文件:
Then load the file with values as follows:
$logic = $this->CI->load->file($path_to_logic, array('foo' => 'bar'), true);
在文件中你将有 $ foo
。
这篇关于CodeIgniter加载带有数据参数的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文