BaseModule.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fec;
  10. use Yii;
  11. use fec\helpers\CConfig;
  12. /**
  13. * @author Terry Zhao <2358269014@qq.com>
  14. * @since 1.0
  15. */
  16. class BaseModule extends \yii\base\Module
  17. {
  18. public $controllerNamespace ;
  19. public $_currentDir ;
  20. public $_currentNameSpace ;
  21. public function init()
  22. {
  23. parent::init();
  24. $theme = CConfig::getCurrentTheme();
  25. # 定义views文件所在路径
  26. $dir = \basename($this->_currentDir);
  27. basename(dirname($_SERVER['PHP_SELF']));
  28. $viewPath = __DIR__ . "/Theme/".$theme."/".strtolower($dir);
  29. $this->setViewPath($viewPath);
  30. # 定义模块专属的layout 文件 appadmin/code/Blog/Theme/default/article/layouts/main.php
  31. //$this->layout = "main.php";
  32. # 加载配置文件
  33. $config_file_dir = $this->_currentDir . '/etc/config.php';
  34. if(file_exists($config_file_dir)){
  35. if(($params_data = (require($config_file_dir))) && !empty($params_data)){
  36. Yii::configure($this, ['params'=> $params_data]);
  37. }
  38. }
  39. $this->params['blockDir'] = str_replace("\\controllers","",$this->controllerNamespace);
  40. }
  41. }