Commit 35018bfb by Qiang Xue

Refactored controller creation process.

parent ad19e332
......@@ -222,7 +222,10 @@ class Module extends Component
/**
* Returns the directory that contains the controller classes according to [[controllerNamespace]].
* Note that in order for this method to return a value, you must define
* an alias for the root namespace of [[controllerNamespace]].
* @return string the directory that contains the controller classes.
* @throws InvalidParamException if there is no alias defined for the root namespace of [[controllerNamespace]].
*/
public function getControllerPath()
{
......@@ -670,13 +673,11 @@ class Module extends Component
}
$className = str_replace(' ', '', ucwords(str_replace('-', ' ', $className))) . 'Controller';
$classFile = $this->getControllerPath() . '/' . $prefix . $className . '.php';
$className = ltrim($this->controllerNamespace . '\\' . str_replace('/', '\\', $prefix) . $className, '\\');
if (strpos($className, '-') !== false || !is_file($classFile)) {
if (strpos($className, '-') !== false || !class_exists($className)) {
return null;
}
Yii::$classMap[$className] = $classFile;
if (is_subclass_of($className, 'yii\base\Controller')) {
return new $className($id, $this);
} elseif (YII_DEBUG) {
......
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