CodeIgniter global variable

后端 未结 4 812
无人共我
无人共我 2021-02-01 10:08

I am using $data in all my views $this->load->view(\'my_view\', $data);

I have also autoload a Controller following this guide Exten

4条回答
  •  野的像风
    2021-02-01 10:32

    I ran into a similar problem earlier today. I found that an easier way, rather than globals, was to use constants. You can define a constants file that will load from your index.php file:

    // Include additional constants
    $defines_file = 'includes/defines.php';
    if (file_exists($defines_file))
    {
        require_once($defines_file);
    } 
    

    Then you can add your constants to the defines.php file:

    define(MY_CONSTANT,'my constant info');
    

    This way they will be available in any file throughout the system either directly: echo MY_CONSTANT; or you can assign them to variables.

    I decided this way would be easier for me as I would only have 1 location to go to when/if I needed to change the constants.

    More: http://codeigniter.com/forums/viewthread/56981/#280205

提交回复
热议问题