diff --git a/framework/yii/gii/Generator.php b/framework/yii/gii/Generator.php
index 5f4257d..aa4f014 100644
--- a/framework/yii/gii/Generator.php
+++ b/framework/yii/gii/Generator.php
@@ -231,7 +231,7 @@ abstract class Generator extends Model
$error = $file->save();
if (is_string($error)) {
$hasError = true;
- $lines[] = "generating $relativePath
$error";
+ $lines[] = "generating $relativePath\n$error";
} else {
$lines[] = $file->operation === CodeFile::OP_NEW ? " generated $relativePath" : " overwrote $relativePath";
}
diff --git a/framework/yii/gii/assets/main.css b/framework/yii/gii/assets/main.css
index 12d2b86..dc0c618 100644
--- a/framework/yii/gii/assets/main.css
+++ b/framework/yii/gii/assets/main.css
@@ -90,9 +90,10 @@ body {
color: white;
padding: 10px;
border-radius: 0;
+ white-space: nowrap;
}
-.default-view-results pre span.error {
+.default-view-results pre .error {
background: #FFE0E1;
color: black;
padding: 1px;
diff --git a/framework/yii/gii/generators/form/Generator.php b/framework/yii/gii/generators/form/Generator.php
index 043fa0f..759978c 100644
--- a/framework/yii/gii/generators/form/Generator.php
+++ b/framework/yii/gii/generators/form/Generator.php
@@ -7,6 +7,10 @@
namespace yii\gii\generators\form;
+use Yii;
+use yii\base\Model;
+use yii\gii\CodeFile;
+
/**
*
* @author Qiang Xue
You may add the following code in an appropriate controller class to invoke the view:
+EOD; + $code = "render($this->getTemplatePath() . '/action.php'); + return $output . highlight_string($code, true); + } + + public function validateModel($attribute, $params) + { + try { + if (class_exists($this->modelClass)) { + if (!is_subclass_of($this->modelClass, Model::className())) { + $this->addError('modelClass', "'{$this->modelClass}' must extend from Model or its child class."); + } + } else { + $this->addError('modelClass', "Class '{$this->modelClass}' does not exist or has syntax error."); + } + } catch (\Exception $e) { + $this->addError('modelClass', "Class '{$this->modelClass}' does not exist or has syntax error."); + return; + } + } + + public function validateViewPath() + { + $path = Yii::getAlias($this->viewPath, false); + if ($path === false || !is_dir($path)) { + $this->addError('viewPath', 'View path does not exist.'); + } + } + + public function getModelAttributes() + { + /** @var Model $model */ + $model = new $this->modelClass; + $model->setScenario($this->scenarioName); + return $model->safeAttributes(); } } diff --git a/framework/yii/gii/generators/form/templates/action.php b/framework/yii/gii/generators/form/templates/action.php new file mode 100644 index 0000000..68168de --- /dev/null +++ b/framework/yii/gii/generators/form/templates/action.php @@ -0,0 +1,8 @@ + +field($generator, 'viewName'); ?> +field($generator, 'modelClass'); ?> +field($generator, 'scenarioName'); ?> +field($generator, 'viewPath'); ?> diff --git a/framework/yii/gii/views/default/view/results.php b/framework/yii/gii/views/default/view/results.php index 0173882..caca404 100644 --- a/framework/yii/gii/views/default/view/results.php +++ b/framework/yii/gii/views/default/view/results.php @@ -18,5 +18,5 @@ use yii\gii\CodeFile; echo '