view.php 1.8 KB
Newer Older
Qiang Xue committed
1 2
<?php

Qiang Xue committed
3
use yii\gii\Generator;
Qiang Xue committed
4
use yii\helpers\Html;
Qiang Xue committed
5
use yii\widgets\ActiveForm;
Qiang Xue committed
6
use yii\gii\components\ActiveField;
Qiang Xue committed
7
use yii\gii\CodeFile;
Qiang Xue committed
8 9

/**
Qiang Xue committed
10 11
 * @var yii\base\View $this
 * @var yii\gii\Generator $generator
12
 * @var string $id
Qiang Xue committed
13
 * @var yii\widgets\ActiveForm $form
Qiang Xue committed
14 15
 * @var string $results
 * @var boolean $hasError
Qiang Xue committed
16
 * @var CodeFile[] $files
Qiang Xue committed
17
 * @var array $answers
Qiang Xue committed
18 19 20
 */

$this->title = $generator->getName();
Alexander Makarov committed
21
$templates = [];
Qiang Xue committed
22 23 24
foreach ($generator->templates as $name => $path) {
	$templates[$name] = "$name ($path)";
}
Qiang Xue committed
25 26
?>
<div class="default-view">
27
	<h1><?=Html::encode($this->title); ?></h1>
Qiang Xue committed
28

29
	<p><?=$generator->getDescription(); ?></p>
Qiang Xue committed
30

Alexander Makarov committed
31
	<?php $form = ActiveForm::begin([
32
		'id' => "$id-generator",
Qiang Xue committed
33
		'successCssClass' => '',
Alexander Makarov committed
34 35
		'fieldConfig' => ['class' => ActiveField::className()],
	]); ?>
Qiang Xue committed
36
		<div class="row">
Qiang Xue committed
37
			<div class="col-lg-8">
Alexander Makarov committed
38
				<?=$this->renderFile($generator->formView(), [
Qiang Xue committed
39 40
					'generator' => $generator,
					'form' => $form,
Alexander Makarov committed
41
				]); ?>
42
				<?=$form->field($generator, 'template')->sticky()
Qiang Xue committed
43
					->label('Code Template')
Qiang Xue committed
44 45 46 47
					->dropDownList($templates)->hint('
						Please select which set of the templates should be used to generated the code.
				'); ?>
				<div class="form-group">
Alexander Makarov committed
48
					<?=Html::submitButton('Preview', ['name' => 'preview', 'class' => 'btn btn-primary']); ?>
Qiang Xue committed
49

Qiang Xue committed
50
					<?php if(isset($files)): ?>
Alexander Makarov committed
51
						<?=Html::submitButton('Generate', ['name' => 'generate', 'class' => 'btn btn-success']); ?>
Qiang Xue committed
52 53
					<?php endif; ?>
				</div>
Qiang Xue committed
54 55
			</div>
		</div>
Qiang Xue committed
56

Qiang Xue committed
57 58
		<?php
		if (isset($results)) {
Alexander Makarov committed
59
			echo $this->render('view/results', [
Qiang Xue committed
60 61 62
				'generator' => $generator,
				'results' => $results,
				'hasError' => $hasError,
Alexander Makarov committed
63
			]);
Qiang Xue committed
64
		} elseif (isset($files)) {
Alexander Makarov committed
65
			echo $this->render('view/files', [
Qiang Xue committed
66 67 68
				'generator' => $generator,
				'files' => $files,
				'answers' => $answers,
Alexander Makarov committed
69
			]);
Qiang Xue committed
70 71
		}
		?>
Qiang Xue committed
72
	<?php ActiveForm::end(); ?>
Qiang Xue committed
73
</div>