baseController.php 725 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace common\components;
  3. use Yii;
  4. use yii\web\Controller;
  5. /**
  6. * 前后台基类
  7. */
  8. class baseController extends Controller{
  9. public $imgUrl,$adminUrl,$frontUrl,$openUrl,$picUrl,$wwwUrl;
  10. public function beforeAction($action){
  11. $hostInfo = Yii::$app->urlManager->getHostInfo();
  12. $parse = parse_url($hostInfo);
  13. $host = $parse['host'];
  14. $pos = strpos($host,'.') + 1;
  15. $pre = substr($host,$pos);
  16. $this->imgUrl = 'http://img.'.$pre;
  17. $this->adminUrl = 'http://a.'.$pre;
  18. $this->frontUrl = 'http://m.'.$pre;
  19. $this->openUrl = 'http://o.'.$pre;
  20. $this->picUrl = 'http://pic.'.$pre;//阿里云oss图床
  21. $this->wwwUrl = 'http://www.'.$pre;
  22. return parent::beforeAction($action);
  23. }
  24. }