Browse Source

Implemented default controller namespace.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
21160338d7
  1. 1
      apps/basic/config/main.php
  2. 16
      framework/yii/base/Module.php

1
apps/basic/config/main.php

@ -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',

16
framework/yii/base/Module.php

@ -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
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';
}
}
}
} }
/** /**

Loading…
Cancel
Save