Browse Source

Merge branch 'master' of github.com:yiisoft/yii2

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
1360f84d3d
  1. 12
      framework/yii/gii/generators/crud/Generator.php
  2. 8
      framework/yii/gii/generators/crud/templates/views/_form.php
  3. 12
      framework/yii/gii/generators/crud/templates/views/_search.php
  4. 4
      framework/yii/gii/generators/crud/templates/views/create.php
  5. 16
      framework/yii/gii/generators/crud/templates/views/index.php
  6. 4
      framework/yii/gii/generators/crud/templates/views/update.php
  7. 10
      framework/yii/gii/generators/crud/templates/views/view.php

12
framework/yii/gii/generators/crud/Generator.php

@ -190,9 +190,9 @@ class Generator extends \yii\gii\Generator
} }
$column = $tableSchema->columns[$attribute]; $column = $tableSchema->columns[$attribute];
if ($column->phpType === 'boolean') { if ($column->phpType === 'boolean') {
return "\$form->field(\$model, '$attribute')->checkbox();"; return "\$form->field(\$model, '$attribute')->checkbox()";
} elseif ($column->type === 'text') { } elseif ($column->type === 'text') {
return "\$form->field(\$model, '$attribute')->textarea(['rows' => 6]);"; return "\$form->field(\$model, '$attribute')->textarea(['rows' => 6])";
} else { } else {
if (preg_match('/^(password|pass|passwd|passcode)$/i', $column->name)) { if (preg_match('/^(password|pass|passwd|passcode)$/i', $column->name)) {
$input = 'passwordInput'; $input = 'passwordInput';
@ -200,9 +200,9 @@ class Generator extends \yii\gii\Generator
$input = 'textInput'; $input = 'textInput';
} }
if ($column->phpType !== 'string' || $column->size === null) { if ($column->phpType !== 'string' || $column->size === null) {
return "\$form->field(\$model, '$attribute')->$input();"; return "\$form->field(\$model, '$attribute')->$input()";
} else { } else {
return "\$form->field(\$model, '$attribute')->$input(['maxlength' => $column->size]);"; return "\$form->field(\$model, '$attribute')->$input(['maxlength' => $column->size])";
} }
} }
} }
@ -216,9 +216,9 @@ class Generator extends \yii\gii\Generator
$tableSchema = $this->getTableSchema(); $tableSchema = $this->getTableSchema();
$column = $tableSchema->columns[$attribute]; $column = $tableSchema->columns[$attribute];
if ($column->phpType === 'boolean') { if ($column->phpType === 'boolean') {
return "\$form->field(\$model, '$attribute')->checkbox();"; return "\$form->field(\$model, '$attribute')->checkbox()";
} else { } else {
return "\$form->field(\$model, '$attribute');"; return "\$form->field(\$model, '$attribute')";
} }
} }

8
framework/yii/gii/generators/crud/templates/views/_form.php

@ -30,15 +30,15 @@ use yii\widgets\ActiveForm;
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-form"> <div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-form">
<?= '<?php' ?> $form = ActiveForm::begin(); ?> <?= "<?php " ?>$form = ActiveForm::begin(); ?>
<?php foreach ($safeAttributes as $attribute) { <?php foreach ($safeAttributes as $attribute) {
echo "\t\t<?=" . $generator->generateActiveField($attribute) . " ?>\n\n"; echo "\t\t<?= " . $generator->generateActiveField($attribute) . " ?>\n\n";
} ?> } ?>
<div class="form-group"> <div class="form-group">
<?= '<?php' ?> echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> <?= "<?= " ?>Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div> </div>
<?= '<?php' ?> ActiveForm::end(); ?> <?= "<?php " ?>ActiveForm::end(); ?>
</div> </div>

12
framework/yii/gii/generators/crud/templates/views/_search.php

@ -23,7 +23,7 @@ use yii\widgets\ActiveForm;
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-search"> <div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-search">
<?= '<?php' ?> $form = ActiveForm::begin([ <?= "<?php " ?>$form = ActiveForm::begin([
'action' => ['index'], 'action' => ['index'],
'method' => 'get', 'method' => 'get',
]); ?> ]); ?>
@ -32,17 +32,17 @@ use yii\widgets\ActiveForm;
$count = 0; $count = 0;
foreach ($generator->getTableSchema()->getColumnNames() as $attribute) { foreach ($generator->getTableSchema()->getColumnNames() as $attribute) {
if (++$count < 6) { if (++$count < 6) {
echo "\t\t<?=" . $generator->generateActiveSearchField($attribute) . " ?>\n"; echo "\t\t<?= " . $generator->generateActiveSearchField($attribute) . " ?>\n\n";
} else { } else {
echo "\t\t<?php // echo " . $generator->generateActiveSearchField($attribute) . " ?>\n"; echo "\t\t<?= // " . $generator->generateActiveSearchField($attribute) . " ?>\n\n";
} }
} }
?> ?>
<div class="form-group"> <div class="form-group">
<?= '<?php' ?> echo Html::submitButton('Search', ['class' => 'btn btn-primary']); ?> <?= "<?= " ?>Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= '<?php' ?> echo Html::resetButton('Reset', ['class' => 'btn btn-default']); ?> <?= "<?= " ?>Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
</div> </div>
<?= '<?php' ?> ActiveForm::end(); ?> <?= "<?php " ?>ActiveForm::end(); ?>
</div> </div>

4
framework/yii/gii/generators/crud/templates/views/create.php

@ -24,9 +24,9 @@ $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-create"> <div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-create">
<h1><?= "<?php" ?> echo Html::encode($this->title); ?></h1> <h1><?= "<?= " ?>Html::encode($this->title) ?></h1>
<?= "<?php" ?> echo $this->render('_form', [ <?= "<?php " ?>echo $this->render('_form', [
'model' => $model, 'model' => $model,
]); ?> ]); ?>

16
framework/yii/gii/generators/crud/templates/views/index.php

@ -15,7 +15,7 @@ echo "<?php\n";
?> ?>
use yii\helpers\Html; use yii\helpers\Html;
use <?= $generator->indexWidgetType === 'grid' ? 'yii\grid\GridView' : 'yii\widgets\ListView' ?>; use <?= $generator->indexWidgetType === 'grid' ? "yii\grid\GridView" : "yii\widgets\ListView" ?>;
/** /**
* @var yii\base\View $this * @var yii\base\View $this
@ -28,16 +28,16 @@ $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-index"> <div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-index">
<h1><?= "<?php" ?> echo Html::encode($this->title); ?></h1> <h1><?= "<?= " ?>Html::encode($this->title) ?></h1>
<?= '<?php' . ($generator->indexWidgetType === 'grid' ? ' //' : '') ?> echo $this->render('_search', ['model' => $searchModel]); ?> <?= "<?php " . ($generator->indexWidgetType === 'grid' ? "// " : "") ?>echo $this->render('_search', ['model' => $searchModel]); ?>
<p> <p>
<?= '<?php' ?> echo Html::a('Create <?= StringHelper::basename($generator->modelClass) ?>', ['create'], ['class' => 'btn btn-success']); ?> <?= "<?= " ?>Html::a('Create <?= StringHelper::basename($generator->modelClass) ?>', ['create'], ['class' => 'btn btn-success']) ?>
</p> </p>
<?php if ($generator->indexWidgetType === 'grid'): ?> <?php if ($generator->indexWidgetType === 'grid'): ?>
<?= "<?php" ?> echo GridView::widget([ <?= "<?php " ?>echo GridView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'filterModel' => $searchModel, 'filterModel' => $searchModel,
'columns' => [ 'columns' => [
@ -48,9 +48,9 @@ $count = 0;
foreach ($generator->getTableSchema()->columns as $column) { foreach ($generator->getTableSchema()->columns as $column) {
$format = $generator->generateColumnFormat($column); $format = $generator->generateColumnFormat($column);
if (++$count < 6) { if (++$count < 6) {
echo "\t\t\t'" . $column->name . ($format === 'text' ? '' : ':' . $format) . "',\n"; echo "\t\t\t'" . $column->name . ($format === 'text' ? "" : ":" . $format) . "',\n";
} else { } else {
echo "\t\t\t// '" . $column->name . ($format === 'text' ? '' : ':' . $format) . "',\n"; echo "\t\t\t// '" . $column->name . ($format === 'text' ? "" : ":" . $format) . "',\n";
} }
} }
?> ?>
@ -59,7 +59,7 @@ foreach ($generator->getTableSchema()->columns as $column) {
], ],
]); ?> ]); ?>
<?php else: ?> <?php else: ?>
<?= "<?php" ?> echo ListView::widget([ <?= "<?php " ?>echo ListView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'item'], 'itemOptions' => ['class' => 'item'],
'itemView' => function ($model, $key, $index, $widget) { 'itemView' => function ($model, $key, $index, $widget) {

4
framework/yii/gii/generators/crud/templates/views/update.php

@ -27,9 +27,9 @@ $this->params['breadcrumbs'][] = 'Update';
?> ?>
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-update"> <div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-update">
<h1><?= "<?php" ?> echo Html::encode($this->title); ?></h1> <h1><?= "<?= " ?>Html::encode($this->title) ?></h1>
<?= "<?php" ?> echo $this->render('_form', [ <?= "<?php " ?>echo $this->render('_form', [
'model' => $model, 'model' => $model,
]); ?> ]); ?>

10
framework/yii/gii/generators/crud/templates/views/view.php

@ -27,24 +27,24 @@ $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-view"> <div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-view">
<h1><?= "<?php" ?> echo Html::encode($this->title); ?></h1> <h1><?= "<?= " ?>Html::encode($this->title) ?></h1>
<p> <p>
<?= '<?php' ?> echo Html::a('Update', ['update', <?= $urlParams ?>], ['class' => 'btn btn-primary']); ?> <?= "<?= " ?>Html::a('Update', ['update', <?= $urlParams ?>], ['class' => 'btn btn-primary']) ?>
<?= '<?php' ?> echo Html::a('Delete', ['delete', <?= $urlParams ?>], [ <?= "<?php " ?>echo Html::a('Delete', ['delete', <?= $urlParams ?>], [
'class' => 'btn btn-danger', 'class' => 'btn btn-danger',
'data-confirm' => Yii::t('app', 'Are you sure to delete this item?'), 'data-confirm' => Yii::t('app', 'Are you sure to delete this item?'),
'data-method' => 'post', 'data-method' => 'post',
]); ?> ]); ?>
</p> </p>
<?= '<?php' ?> echo DetailView::widget([ <?= "<?php " ?>echo DetailView::widget([
'model' => $model, 'model' => $model,
'attributes' => [ 'attributes' => [
<?php <?php
foreach ($generator->getTableSchema()->columns as $column) { foreach ($generator->getTableSchema()->columns as $column) {
$format = $generator->generateColumnFormat($column); $format = $generator->generateColumnFormat($column);
echo "\t\t\t'" . $column->name . ($format === 'text' ? '' : ':' . $format) . "',\n"; echo "\t\t\t'" . $column->name . ($format === 'text' ? "" : ":" . $format) . "',\n";
} }
?> ?>
], ],

Loading…
Cancel
Save