index.php 2.58 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
 */

26
$this->title = <?= $generator->generateString(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

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

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

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

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

Qiang Xue committed
81
</div>