AdminModule.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 AdminModule extends \yii\base\Module
  17. {
  18. public $controllerNamespace ;
  19. public $_currentDir ;
  20. public $_currentNameSpace ;
  21. public function init()
  22. {
  23. parent::init();
  24. isset($this->_currentDir) && $this->configModuleParams();
  25. # 默认layout文件
  26. $this->layout = $this->layout ? $this->layout : "main.php";
  27. }
  28. public function configModuleParams(){
  29. # 配置config文件
  30. $config_file_dir = $this->_currentDir . '/etc/config.php';
  31. if($this->_currentDir && file_exists($config_file_dir)){
  32. $params_data = (require($config_file_dir));
  33. }
  34. # 设置参数
  35. $params_data['_currentDir'] = $this->_currentDir;
  36. $params_data['_currentNameSpace'] = $this->_currentNameSpace;
  37. $params = $this->params;
  38. if(is_array($params) && !empty($params)){
  39. $params_data = \yii\helpers\ArrayHelper::merge($params,$params_data);
  40. }
  41. Yii::configure($this, ['params'=> $params_data]);
  42. }
  43. /*
  44. public function init()
  45. {
  46. parent::init();
  47. $theme = CConfig::getCurrentTheme();
  48. # 定义views文件所在路径
  49. $dir = \basename($this->_currentDir);
  50. basename(dirname($_SERVER['PHP_SELF']));
  51. $viewPath = __DIR__ . "/Theme/".$theme."/".strtolower($dir);
  52. $this->setViewPath($viewPath);
  53. # 定义模块专属的layout 文件 appadmin/code/Blog/Theme/default/article/layouts/main.php
  54. //$this->layout = "main.php";
  55. # 加载配置文件
  56. $config_file_dir = $this->_currentDir . '/etc/config.php';
  57. if(file_exists($config_file_dir)){
  58. if(($params_data = (require($config_file_dir))) && !empty($params_data)){
  59. Yii::configure($this, ['params'=> $params_data]);
  60. }
  61. }
  62. $this->params['blockDir'] = str_replace("\\controllers","",$this->controllerNamespace);
  63. }
  64. */
  65. }