代码点火器,使用全局变量


codeigniter, using global variable

我有一个带有 5 个控制器的代码点火器应用程序,一个是"基础",其余的继承它,我在基库中使用全局变量在视图中加载,但它不起作用,当我加载视图时我得到(未定义的变量)我该如何解决这个问题?

我在底座中使用这个函数来加载视图


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

你可以使用config class。

$this->config->set_item('global_variable', $my_var);

现在,您可以在任何地方使用此变量

$this->config->item('global_variable');

尝试使用define()而不是全局来设置变量 - http://php.net/manual/en/function.define.php