CodeIgniter - best place to declare global variable

前端 未结 6 1942
逝去的感伤
逝去的感伤 2020-11-28 10:27

I just want to use a $variable at several places: not only views and controllers, but also in the routes.php and other configuration files.

6条回答
  •  再見小時候
    2020-11-28 11:05

    There is a file in /application/config called constants.php

    I normally put all mine in there with a comment to easily see where they are:

    /**
     * Custom defines
     */
    define('blah', 'hello mum!');
    $myglobalvar = 'hey there';
    

    After your index.php is loaded, it loads the /core/CodeIgniter.php file, which then in turn loads the common functions file /core/Common.php and then /application/constants.php so in the chain of things it's the forth file to be loaded.

提交回复
热议问题