1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use yii\helpers\Inflector; |
4
|
|
|
use yii\helpers\StringHelper; |
5
|
|
|
use yii\helpers\VarDumper; |
6
|
|
|
use cornernote\gii\helpers\TabPadding; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @var yii\web\View $this |
10
|
|
|
* @var schmunk42\giiant\generators\crud\Generator $generator |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
$urlParams = $generator->generateUrlParams(); |
14
|
|
|
$nameAttribute = $generator->getNameAttribute(); |
15
|
|
|
|
16
|
|
|
/** @var \yii\db\ActiveRecord $model */ |
17
|
|
|
$model = new $generator->modelClass; |
18
|
|
|
$safeAttributes = $model->safeAttributes(); |
19
|
|
|
if (empty($safeAttributes)) { |
20
|
|
|
$safeAttributes = $model->getTableSchema()->columnNames; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
echo "<?php\n"; |
24
|
|
|
?> |
25
|
|
|
|
26
|
|
|
use yii\helpers\Html; |
27
|
|
|
use yii\helpers\Url; |
28
|
|
|
use yii\bootstrap\ButtonDropdown; |
29
|
|
|
use <?= $generator->indexWidgetType === 'grid' ? "yii\\grid\\GridView" : "yii\\widgets\\ListView" ?>; |
30
|
|
|
use cornernote\returnurl\ReturnUrl; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var yii\web\View $this |
34
|
|
|
* @var yii\data\ActiveDataProvider $dataProvider |
35
|
|
|
* @var <?= ltrim($generator->searchModelClass, '\\') ?> $searchModel |
36
|
|
|
*/ |
37
|
|
|
|
38
|
|
|
$this->title = <?= $generator->generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>; |
39
|
|
|
$this->params['breadcrumbs'][] = $this->title; |
40
|
|
|
?> |
41
|
|
|
|
42
|
|
|
<div class="<?= Inflector::camel2id(StringHelper::basename($generator->modelClass), '-', true) ?>-index"> |
43
|
|
|
|
44
|
|
|
<div class="clearfix"> |
45
|
|
|
|
46
|
|
|
<p class="pull-left"> |
47
|
|
|
<?= "<?= " ?>Html::a('<span class="fa fa-plus"></span> ' . <?= $generator->generateString('Create') ?> . ' ' . <?= $generator->generateString(Inflector::camel2words(StringHelper::basename($generator->modelClass))) ?>, ['create', 'ru' => ReturnUrl::getToken()], ['class' => 'btn btn-success']) ?> |
48
|
|
|
<?= "<?= " ?>Html::button('<span class="fa fa-search"></span> ' . <?= $generator->generateString('Search') ?> . ' ' . <?= $generator->generateString(Inflector::pluralize(Inflector::camel2words(StringHelper::basename($generator->modelClass)))) ?>, ['class' => 'btn btn-info', 'data-toggle' => 'modal', 'data-target' => '#<?= Inflector::camel2id(StringHelper::basename($generator->modelClass), '-', true) ?>-searchModal']) ?> |
49
|
|
|
</p> |
50
|
|
|
|
51
|
|
|
<div class="pull-right"> |
52
|
|
|
<?php |
53
|
|
|
$items = []; |
54
|
|
|
$model = new $generator->modelClass; |
55
|
|
|
foreach ($generator->getModelRelations($model) AS $relation) { |
56
|
|
|
// relation dropdown links |
57
|
|
|
$iconType = ($relation->multiple) ? 'arrow-right' : 'arrow-left'; |
58
|
|
|
if ($generator->isPivotRelation($relation)) { |
59
|
|
|
$iconType = 'random'; |
60
|
|
|
} |
61
|
|
|
$controller = $generator->pathPrefix . Inflector::camel2id( |
62
|
|
|
StringHelper::basename($relation->modelClass), |
63
|
|
|
'-', |
64
|
|
|
true |
65
|
|
|
); |
66
|
|
|
$route = $generator->createRelationRoute($relation,'index'); |
67
|
|
|
$label = Inflector::titleize(StringHelper::basename($relation->modelClass), '-', true); |
|
|
|
|
68
|
|
|
$items[] = [ |
69
|
|
|
'label' => '<i class="fa fa-' . $iconType . '"></i> ' . $label, |
70
|
|
|
'url' => [$route] |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
?> |
74
|
|
|
|
75
|
|
|
<?= "<?php \n" ?> |
76
|
|
|
/* |
77
|
|
|
echo ButtonDropdown::widget([ |
78
|
|
|
'id' => 'giiant-relations', |
79
|
|
|
'encodeLabel' => false, |
80
|
|
|
'label' => '<span class="fa fa-paperclip"></span> ' . <?= $generator->generateString('Relations') ?>, |
81
|
|
|
'dropdown' => [ |
82
|
|
|
'options' => [ |
83
|
|
|
'class' => 'dropdown-menu-right' |
84
|
|
|
], |
85
|
|
|
'encodeLabels' => false, |
86
|
|
|
'items' => <?= TabPadding::pad(VarDumper::export($items), 5) ?>, |
87
|
|
|
], |
88
|
|
|
]); |
89
|
|
|
*/ |
90
|
|
|
<?= "?>" ?> |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
</div> |
94
|
|
|
|
95
|
|
|
</div> |
96
|
|
|
|
97
|
|
|
<?= "<?php " . ($generator->indexWidgetType === 'grid' ? '' : '') ?>echo $this->render('_search', ['model' => $searchModel]); ?> |
98
|
|
|
|
99
|
|
|
<?php if ($generator->indexWidgetType === 'grid'): ?> |
100
|
|
|
<div class="table-responsive"> |
101
|
|
|
<?= "<?= " ?>GridView::widget([ |
102
|
|
|
'layout' => '{summary}{pager}{items}{pager}', |
103
|
|
|
'dataProvider' => $dataProvider, |
104
|
|
|
'filterModel' => $searchModel, |
105
|
|
|
'columns' => [ |
106
|
|
|
<?php |
107
|
|
|
$class = $generator->modelClass; |
108
|
|
|
$actionButtonColumn = <<<PHP |
109
|
|
|
[ |
110
|
|
|
'class' => '{$generator->actionButtonClass}', |
111
|
|
|
'urlCreator' => function (\$action, \$model, \$key, \$index) { |
112
|
|
|
/** @var {$class} \$model */ |
113
|
|
|
// using the column name as key, not mapping to 'id' like the standard generator |
114
|
|
|
\$params = is_array(\$key) ? \$key : [\$model->primaryKey()[0] => (string)\$key]; |
115
|
|
|
\$params[0] = Yii::\$app->controller->id ? Yii::\$app->controller->id . '/' . \$action : \$action; |
116
|
|
|
\$params['ru'] = ReturnUrl::getToken(); |
117
|
|
|
return Url::toRoute(\$params); |
118
|
|
|
}, |
119
|
|
|
'contentOptions' => ['nowrap' => 'nowrap'] |
120
|
|
|
], |
121
|
|
|
PHP; |
122
|
|
|
|
123
|
|
|
// action buttons first |
124
|
|
|
echo $actionButtonColumn; |
125
|
|
|
|
126
|
|
|
$count = 0; |
127
|
|
|
echo "\n"; // code-formatting |
128
|
|
|
|
129
|
|
|
foreach ($safeAttributes as $attribute) { |
130
|
|
|
$format = $generator->columnFormat($attribute,$model); |
131
|
|
|
if ($format == false) continue; |
132
|
|
|
$format = (++$count < 10) ? "{$format},\n" : " /*" . trim($format) . "*/\n"; |
133
|
|
|
echo TabPadding::pad($format, 2, true); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
?> |
137
|
|
|
], |
138
|
|
|
]); ?> |
139
|
|
|
</div> |
140
|
|
|
|
141
|
|
|
<?php else: ?> |
142
|
|
|
<?= "<?= " ?> ListView::widget([ |
143
|
|
|
'dataProvider' => $dataProvider, |
144
|
|
|
'itemOptions' => ['class' => 'item'], |
145
|
|
|
'itemView' => function ($model, $key, $index, $widget) { |
146
|
|
|
return Html::a(Html::encode($model-><?= $nameAttribute ?>), ['view', <?= $urlParams ?>]); |
147
|
|
|
}, |
148
|
|
|
]); ?> |
149
|
|
|
|
150
|
|
|
<?php endif; ?> |
151
|
|
|
</div> |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: