Commit 21160338 by Qiang Xue

Implemented default controller namespace.

parent 8435285c
...@@ -4,7 +4,6 @@ return array( ...@@ -4,7 +4,6 @@ return array(
'id' => 'bootstrap', 'id' => 'bootstrap',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'preload' => array('log'), 'preload' => array('log'),
'controllerNamespace' => 'app\controllers',
'modules' => array( 'modules' => array(
// 'debug' => array( // 'debug' => array(
// 'class' => 'yii\debug\Module', // 'class' => 'yii\debug\Module',
......
...@@ -88,7 +88,11 @@ abstract class Module extends Component ...@@ -88,7 +88,11 @@ abstract class Module extends Component
*/ */
public $controllerMap = array(); public $controllerMap = array();
/** /**
* @var string the namespace that controller classes are in. Default is to use global namespace. * @var string the namespace that controller classes are in. If not set,
* it will use the "controllers" sub-namespace under the namespace of this module.
* For example, if the namespace of this module is "foo\bar", then the default
* controller namespace would be "foo\bar\controllers".
* If the module is an application, it will default to "app\controllers".
*/ */
public $controllerNamespace; public $controllerNamespace;
/** /**
...@@ -178,6 +182,16 @@ abstract class Module extends Component ...@@ -178,6 +182,16 @@ abstract class Module extends Component
public function init() public function init()
{ {
$this->preloadComponents(); $this->preloadComponents();
if ($this->controllerNamespace === null) {
if ($this instanceof Application) {
$this->controllerNamespace = 'app\\controllers';
} else {
$class = get_class($this);
if (($pos = strrpos($class, '\\')) !== false) {
$this->controllerNamespace = substr($class, 0, $pos) . '\\controllers';
}
}
}
} }
/** /**
......
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