在yii中定义全局变量最好的地方是入口脚本处。也就是web目录中的index.php文件

比如我们在defined('YII_ENV') or define('YII_ENV', 'dev');后写上

defined('ZYL_HEHE') or define('ZYL_HEHE','zhyoulun-hehe');

并在我们教程(1)中建立的views/zhyoulun/helloworld.php文件里写上

<?php
echo 'hello world!';

//全局变量
echo constant('ZYL_HEHE');
?>

訪问网址http://localhost/basic/web/index.php?r=zhyoulun/helloworld

Yii Framework2.0开发教程(4)在yii中定义全局变量


參考:http://www.yiichina.com/guide/2/structure-entry-scripts


转载请注明出处:http://blog.csdn.net/zhyoulun/article/details/40458355

相关文章:

  • 2021-06-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-21
  • 2021-07-11
  • 2021-07-23
猜你喜欢
  • 2021-07-05
  • 2021-11-13
  • 2021-10-15
  • 2022-01-21
  • 2021-08-27
  • 2021-12-14
相关资源
相似解决方案