简体   繁体   中英

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?

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.

$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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM