CodeIgniter - best place to declare global variable

前端 未结 6 1953
逝去的感伤
逝去的感伤 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:20

    The best place to declare global variable in codeigniter is the constants.php file in the directory /application/config

    You can define your global variable as follows

    /**
     * Custom definitions
     */
    define('first_custom_variable', 'thisisit');
    $yourglobalvariable = 'thisisimyglobalvariable';
    

提交回复
热议问题