ConsoleController.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. ?>
  10. <?php
  11. namespace fecshop\app\console\modules;
  12. use fec\controllers\FecController;
  13. use Yii;
  14. /**
  15. * @author Terry Zhao <2358269014@qq.com>
  16. * @since 1.0
  17. */
  18. class ConsoleController extends FecController
  19. {
  20. public $blockNamespace;
  21. /**
  22. * get current block
  23. * you can change $this->blockNamespace.
  24. */
  25. public function getBlock($blockName = '')
  26. {
  27. if (!$blockName) {
  28. $blockName = $this->action->id;
  29. }
  30. if (!$this->blockNamespace) {
  31. $this->blockNamespace = Yii::$app->controller->module->blockNamespace;
  32. }
  33. if (!$this->blockNamespace) {
  34. throw new \yii\web\HttpException(406, 'blockNamespace is empty , you should config it in module->blockNamespace or controller blockNamespace ');
  35. }
  36. $relativeFile = '\\'.$this->blockNamespace;
  37. $relativeFile .= '\\'.$this->id.'\\'.ucfirst($blockName);
  38. //查找是否在rewriteMap中存在重写
  39. $relativeFile = Yii::mapGetName($relativeFile);
  40. return new $relativeFile();
  41. }
  42. }