Commit 71222c1f by Qiang Xue

Merge pull request #992 from lucianobaraglia/master

GII sub-modules support [skip ci]
parents 3667e031 c2457f95
...@@ -333,7 +333,20 @@ abstract class Module extends Component ...@@ -333,7 +333,20 @@ abstract class Module extends Component
*/ */
public function hasModule($id) public function hasModule($id)
{ {
return isset($this->_modules[$id]); if (strpos($id, '/') === false) {
return isset($this->_modules[$id]);
} else {
// it's a sub-module
$ids = explode('/', $id);
$module = $this;
foreach ($ids as $id) {
if (!isset($module->_modules[$id])) {
return false;
}
$module = $module->getModule($id);
}
return true;
}
} }
/** /**
...@@ -345,13 +358,23 @@ abstract class Module extends Component ...@@ -345,13 +358,23 @@ abstract class Module extends Component
*/ */
public function getModule($id, $load = true) public function getModule($id, $load = true)
{ {
if (isset($this->_modules[$id])) { if (strpos($id, '/') === false) {
if ($this->_modules[$id] instanceof Module) { if (isset($this->_modules[$id])) {
return $this->_modules[$id]; if ($this->_modules[$id] instanceof Module) {
} elseif ($load) { return $this->_modules[$id];
Yii::trace("Loading module: $id", __METHOD__); } elseif ($load) {
return $this->_modules[$id] = Yii::createObject($this->_modules[$id], $id, $this); Yii::trace("Loading module: $id", __METHOD__);
return $this->_modules[$id] = Yii::createObject($this->_modules[$id], $id, $this);
}
}
} else {
// it's a sub-module
$ids = explode('/', $id);
$module = $this;
foreach ($ids as $id) {
$module = $module->getModule($id);
} }
return $module;
} }
return null; return null;
} }
......
...@@ -197,7 +197,7 @@ class Generator extends \yii\gii\Generator ...@@ -197,7 +197,7 @@ class Generator extends \yii\gii\Generator
*/ */
public function getModule() public function getModule()
{ {
if (($pos = strpos($this->controller, '/')) !== false) { if (($pos = strrpos($this->controller, '/')) !== false) {
$id = substr($this->controller, 0, $pos); $id = substr($this->controller, 0, $pos);
if (($module = Yii::$app->getModule($id)) !== null) { if (($module = Yii::$app->getModule($id)) !== null) {
return $module; return $module;
......
...@@ -87,18 +87,17 @@ class Generator extends \yii\gii\Generator ...@@ -87,18 +87,17 @@ class Generator extends \yii\gii\Generator
$output = <<<EOD $output = <<<EOD
<p>The module has been generated successfully.</p> <p>The module has been generated successfully.</p>
<p>To access the module, you need to modify the application configuration as follows:</p> <p>To access the module, you need to add this to your application configuration:</p>
EOD; EOD;
$code = <<<EOD $code = <<<EOD
<?php <?php
return array( ......
'modules'=>array( 'modules' => array(
'{$this->moduleID}' => array( '{$this->moduleID}' => array(
'class' => '{$this->moduleClass}', 'class' => '{$this->moduleClass}',
), ),
), ),
...... ......
);
EOD; EOD;
return $output . '<pre>' . highlight_string($code, true) . '</pre>'; return $output . '<pre>' . highlight_string($code, true) . '</pre>';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment