index.php 2.27 KB
Newer Older
Qiang Xue committed
1
<?php
Qiang Xue committed
2 3 4 5

use yii\helpers\Inflector;
use yii\helpers\StringHelper;

Qiang Xue committed
6
/**
Alexander Makarov committed
7
 * @var yii\web\View $this
Qiang Xue committed
8
 * @var yii\gii\generators\crud\Generator $generator
Qiang Xue committed
9 10
 */

Qiang Xue committed
11
$urlParams = $generator->generateUrlParams();
Qiang Xue committed
12 13 14
$nameAttribute = $generator->getNameAttribute();

echo "<?php\n";
Qiang Xue committed
15 16
?>

Qiang Xue committed
17
use yii\helpers\Html;
18
use <?= $generator->indexWidgetType === 'grid' ? "yii\\grid\\GridView" : "yii\\widgets\\ListView" ?>;
Qiang Xue committed
19 20

/**
Alexander Makarov committed
21
 * @var yii\web\View $this
Qiang Xue committed
22
 * @var yii\data\ActiveDataProvider $dataProvider
Alexander Makarov committed
23
 * @var <?= ltrim($generator->searchModelClass, '\\') ?> $searchModel
Qiang Xue committed
24 25
 */

Alexander Makarov committed
26
$this->title = '<?= Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass))) ?>';
Qiang Xue committed
27
$this->params['breadcrumbs'][] = $this->title;
Qiang Xue committed
28
?>
Alexander Makarov committed
29
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-index">
Qiang Xue committed
30

31
	<h1><?= "<?= " ?>Html::encode($this->title) ?></h1>
Qiang Xue committed
32

33
	<?= "<?php " . ($generator->indexWidgetType === 'grid' ? "// " : "") ?>echo $this->render('_search', ['model' => $searchModel]); ?>
Qiang Xue committed
34

Qiang Xue committed
35
	<p>
36
		<?= "<?= " ?>Html::a('Create <?= StringHelper::basename($generator->modelClass) ?>', ['create'], ['class' => 'btn btn-success']) ?>
Qiang Xue committed
37
	</p>
Qiang Xue committed
38 39

<?php if ($generator->indexWidgetType === 'grid'): ?>
40
	<?= "<?php " ?>echo GridView::widget([
Qiang Xue committed
41 42
		'dataProvider' => $dataProvider,
		'filterModel' => $searchModel,
Alexander Makarov committed
43 44
		'columns' => [
			['class' => 'yii\grid\SerialColumn'],
45

Qiang Xue committed
46 47
<?php
$count = 0;
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
if (($tableSchema = $generator->getTableSchema()) === false) {
	foreach ($generator->getColumnNames() as $name) {
		if (++$count < 6) {
			echo "\t\t\t'" . $name . "',\n";
		} else {
			echo "\t\t\t// '" . $name . "',\n";
		}
	}
} else {
	foreach ($tableSchema->columns as $column) {
		$format = $generator->generateColumnFormat($column);
		if (++$count < 6) {
			echo "\t\t\t'" . $column->name . ($format === 'text' ? "" : ":" . $format) . "',\n";
		} else {
			echo "\t\t\t// '" . $column->name . ($format === 'text' ? "" : ":" . $format) . "',\n";
		}
Qiang Xue committed
64 65 66
	}
}
?>
Qiang Xue committed
67

Alexander Makarov committed
68 69 70
			['class' => 'yii\grid\ActionColumn'],
		],
	]); ?>
Qiang Xue committed
71
<?php else: ?>
72
	<?= "<?php " ?>echo ListView::widget([
Qiang Xue committed
73
		'dataProvider' => $dataProvider,
Alexander Makarov committed
74
		'itemOptions' => ['class' => 'item'],
Qiang Xue committed
75
		'itemView' => function ($model, $key, $index, $widget) {
Alexander Makarov committed
76
			return Html::a(Html::encode($model-><?= $nameAttribute ?>), ['view', <?= $urlParams ?>]);
Qiang Xue committed
77
		},
Alexander Makarov committed
78
	]); ?>
Qiang Xue committed
79
<?php endif; ?>
Qiang Xue committed
80

Qiang Xue committed
81
</div>