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

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

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

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

echo "<?php\n";
Qiang Xue committed
13 14
?>

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

18 19 20
/* @var $this yii\web\View */
<?= !empty($generator->searchModelClass) ? "/* @var \$searchModel " . ltrim($generator->searchModelClass, '\\') . " */\n" : '' ?>
/* @var $dataProvider yii\data\ActiveDataProvider */
Qiang Xue committed
21

22
$this->title = <?= $generator->generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>;
Qiang Xue committed
23
$this->params['breadcrumbs'][] = $this->title;
Qiang Xue committed
24
?>
Alexander Makarov committed
25
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass)) ?>-index">
Qiang Xue committed
26

27
    <h1><?= "<?= " ?>Html::encode($this->title) ?></h1>
28 29 30
<?php if(!empty($generator->searchModelClass)): ?>
<?= "    <?php " . ($generator->indexWidgetType === 'grid' ? "// " : "") ?>echo $this->render('_search', ['model' => $searchModel]); ?>
<?php endif; ?>
Qiang Xue committed
31

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

<?php if ($generator->indexWidgetType === 'grid'): ?>
37 38
    <?= "<?= " ?>GridView::widget([
        'dataProvider' => $dataProvider,
39
        <?= !empty($generator->searchModelClass) ? "'filterModel' => \$searchModel,\n        'columns' => [\n" : "'columns' => [\n"; ?>
40
            ['class' => 'yii\grid\SerialColumn'],
41

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

64 65 66
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
Qiang Xue committed
67
<?php else: ?>
68 69 70 71 72 73 74
    <?= "<?= " ?>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
75
<?php endif; ?>
Qiang Xue committed
76

Qiang Xue committed
77
</div>