CodeIgniter - best place to declare global variable

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

    inside file application/conf/contants.php :

    global $myVAR;
    $myVAR= 'http://'.$_SERVER["HTTP_HOST"].'/';
    

    and put in some header file or inside of any function:

    global $myVAR;
    $myVAR= 'some value';
    

提交回复
热议问题