[英]codeigniter, using global variable
i have a codeigniter application with 5 controllers one is the 'base' and the rest are inheriting form it, i am using global variable in the base to load in the view but it's not working i get (Undefined variable) when i load the view how can I fix this? 我有一个带有5个控制器的codeigniter应用程序,一个是'base',其余的都继承自它,我正在使用base中的global变量在视图中加载,但无法正常工作,我在加载视图时得到了(Undefined variable)我怎样才能解决这个问题?
i'm using this function in the base to load the views 我在基地使用此功能来加载视图
function _setContent($tplFile) {
ob_start();
$this->load->view($this->theme_dir . '/' . $tplFile, $this->tplData);
$_content = ob_get_contents();
ob_end_clean();
$this->tplData['_content'] = $_content;
$this->load->view($this->theme_dir . '/default', $this->tplData);
}
$this->tplData // is the global variable
you can use config class. 您可以使用config类。
$this->config->set_item('global_variable', $my_var);
now you can use this variable wherever you want 现在您可以在任何地方使用此变量
$this->config->item('global_variable');
尝试使用define()
而不是global来设置变量-http://php.net/manual/zh/function.define.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.