diff --git a/framework/yii/base/Application.php b/framework/yii/base/Application.php index a5d2c1d..0d0dd89 100644 --- a/framework/yii/base/Application.php +++ b/framework/yii/base/Application.php @@ -169,7 +169,7 @@ abstract class Application extends Module public function registerErrorHandlers() { if (YII_ENABLE_ERROR_HANDLER) { - //ini_set('display_errors', 0); + ini_set('display_errors', 0); set_exception_handler(array($this, 'handleException')); set_error_handler(array($this, 'handleError'), error_reporting()); if ($this->memoryReserveSize > 0) { @@ -419,7 +419,6 @@ abstract class Application extends Module // disable error capturing to avoid recursive errors while handling exceptions restore_error_handler(); restore_exception_handler(); - try { $this->logException($exception); if (($handler = $this->getErrorHandler()) !== null) { diff --git a/framework/yii/gii/assets/gii.js b/framework/yii/gii/assets/gii.js index d91be6d..ac701e0 100644 --- a/framework/yii/gii/assets/gii.js +++ b/framework/yii/gii/assets/gii.js @@ -28,7 +28,7 @@ yii.gii = (function ($) { } $(this).before('
You may add the following code in an appropriate controller class to invoke the view:
--$code -+
$codeEOD; } diff --git a/framework/yii/gii/generators/form/templates/action.php b/framework/yii/gii/generators/form/templates/action.php index 3884b02..fc5830e 100644 --- a/framework/yii/gii/generators/form/templates/action.php +++ b/framework/yii/gii/generators/form/templates/action.php @@ -8,8 +8,10 @@ use yii\helpers\Inflector; * @var yii\base\View $this * @var yii\gii\generators\form\Generator $generator */ + +echo " - + public function actionviewName), '_')); ?>() { $model = new modelClass; ?>scenarioName) ? '' : "(array('scenario' => '{$generator->scenarioName}'))"; ?>; diff --git a/framework/yii/gii/generators/form/templates/form.php b/framework/yii/gii/generators/form/templates/form.php index 53cf5e6..0635746 100644 --- a/framework/yii/gii/generators/form/templates/form.php +++ b/framework/yii/gii/generators/form/templates/form.php @@ -5,8 +5,9 @@ * @var yii\base\View $this * @var yii\gii\generators\form\Generator $generator */ + +echo " - use yii\helpers\Html; use yii\widgets\ActiveForm; diff --git a/framework/yii/gii/generators/form/views/form.php b/framework/yii/gii/generators/form/views/form.php index f276688..c04a26e 100644 --- a/framework/yii/gii/generators/form/views/form.php +++ b/framework/yii/gii/generators/form/views/form.php @@ -4,8 +4,7 @@ * @var yii\widgets\ActiveForm $form * @var yii\gii\generators\form\Generator $generator */ -?> -field($generator, 'viewName'); ?> -field($generator, 'modelClass'); ?> -field($generator, 'scenarioName'); ?> -field($generator, 'viewPath'); ?> +echo $form->field($generator, 'viewName'); +echo $form->field($generator, 'modelClass'); +echo $form->field($generator, 'scenarioName'); +echo $form->field($generator, 'viewPath'); diff --git a/framework/yii/gii/generators/module/Generator.php b/framework/yii/gii/generators/module/Generator.php index bf47b2b..1955ec5 100644 --- a/framework/yii/gii/generators/module/Generator.php +++ b/framework/yii/gii/generators/module/Generator.php @@ -7,18 +7,33 @@ namespace yii\gii\generators\module; +use Yii; +use yii\gii\CodeFile; +use yii\helpers\Html; +use yii\helpers\StringHelper; + /** + * This generator will generate the skeleton code needed by a module. * * @author Qiang Xue
admin
.',
+ 'moduleClass' => 'This is the fully qualified class name of the module, e.g., app\modules\admin\Module
.',
+ );
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function successMessage()
+ {
+ if (Yii::$app->hasModule($this->moduleID)) {
+ $link = Html::a('try it now', Yii::$app->getUrlManager()->createUrl($this->moduleID), array('target' => '_blank'));
+ return "The module has been generated successfully. You may $link.";
+ }
+
+ $output = <<To access the module, you need to modify the application configuration as follows:
+EOD; + $code = <<' . highlight_string($code, true) . ''; + } + + /** + * @inheritdoc + */ + public function requiredTemplates() + { + return array( + 'module.php', + 'controller.php', + 'view.php', + ); + } + + /** + * @inheritdoc + */ public function generate() { - return array(); + $files = array(); + $modulePath = $this->getModulePath(); + $templatePath = $this->getTemplatePath(); + $files[] = new CodeFile( + $modulePath . '/' . StringHelper::basename($this->moduleClass) . '.php', + $this->render("$templatePath/module.php") + ); + $files[] = new CodeFile( + $modulePath . '/controllers/DefaultController.php', + $this->render("$templatePath/controller.php") + ); + $files[] = new CodeFile( + $modulePath . '/views/default/index.php', + $this->render("$templatePath/view.php") + ); + + return $files; + } + + /** + * Validates [[moduleClass]] to make sure it is a fully qualified class name. + */ + public function validateModuleClass() + { + if (strpos($this->moduleClass, '\\') === false || Yii::getAlias('@' . str_replace('\\', '/', $this->moduleClass)) === false) { + $this->addError('moduleClass', 'Module class must be properly namespaced.'); + } + } + + /** + * @return boolean the directory that contains the module class + */ + public function getModulePath() + { + return Yii::getAlias('@' . str_replace('\\', '/', substr($this->moduleClass, 0, strrpos($this->moduleClass, '\\')))); + } + + /** + * @return string the controller namespace of the module. + */ + public function getControllerNamespace() + { + return substr($this->moduleClass, 0, strrpos($this->moduleClass, '\\')) . '\controllers'; } } diff --git a/framework/yii/gii/generators/module/templates/controller.php b/framework/yii/gii/generators/module/templates/controller.php new file mode 100644 index 0000000..34dd961 --- /dev/null +++ b/framework/yii/gii/generators/module/templates/controller.php @@ -0,0 +1,21 @@ + + +namespace getControllerNamespace(); ?>; + +use yii\web\Controller; + +class DefaultController extends Controller +{ + public function actionIndex() + { + $this->render('index'); + } +} diff --git a/framework/yii/gii/generators/module/templates/module.php b/framework/yii/gii/generators/module/templates/module.php new file mode 100644 index 0000000..8841473 --- /dev/null +++ b/framework/yii/gii/generators/module/templates/module.php @@ -0,0 +1,29 @@ +moduleClass; +$pos = strrpos($className, '\\'); +$ns = ltrim(substr($className, 0, $pos), '\\'); +$className = substr($className, $pos + 1); + +echo " + +namespace + + +class extends \yii\web\Module +{ + public $controllerNamespace = 'getControllerNamespace(); ?>'; + + public function init() + { + parent::init(); + + // custom initialization code goes here + } +} diff --git a/framework/yii/gii/generators/module/templates/view.php b/framework/yii/gii/generators/module/templates/view.php new file mode 100644 index 0000000..d0e1ce6 --- /dev/null +++ b/framework/yii/gii/generators/module/templates/view.php @@ -0,0 +1,18 @@ + +
+ This is the view content for action " echo $this->context->action->id; ?>". + The action belongs to the controller " echo get_class($this->context); ?>" + in the " echo $this->context->module->id; ?>" module. +
+
+ You may customize this page by editing the following file:
+ echo __FILE__; ?>
+