1 | <?php |
||
20 | class DocumentsColumn extends \hipanel\grid\DataColumn |
||
21 | { |
||
22 | public $format = 'raw'; |
||
23 | |||
24 | public $type; |
||
25 | |||
26 | public function init() |
||
32 | |||
33 | public function getDataCellValue($model, $key, $index) |
||
34 | { |
||
35 | return ArraySpoiler::widget([ |
||
36 | 'mode' => ArraySpoiler::MODE_SPOILER, |
||
37 | 'data' => parent::getDataCellValue($model, $key, $index), |
||
38 | 'delimiter' => ' ', |
||
39 | 'formatter' => function ($doc) { |
||
40 | return Html::a( |
||
41 | FontIcon::i('fa-file-pdf-o') . date(' M Y', strtotime($doc->validity_start)), |
||
42 | ["/file/{$doc->file_id}/{$doc->filename}", 'nocache' => 1], |
||
43 | [ |
||
44 | 'target' => '_blank', |
||
45 | 'class' => 'btn btn-app pull-left', |
||
46 | 'style' => 'width: 8em;', |
||
47 | ] |
||
48 | ); |
||
49 | }, |
||
50 | 'template' => '<div class="text-right clearfix" style="margin-bottom: 10px;padding-left: 10px;">' . $this->generateManagementButtons($model) . '{button}</div><div>{visible}{hidden}</div>', |
||
51 | 'visibleCount' => 3, |
||
52 | 'button' => [ |
||
53 | 'label' => FontIcon::i('fa-history') . ' ' . Yii::t('hipanel', 'Show all'), |
||
54 | 'class' => 'btn btn-xs btn-default', |
||
55 | 'data' => [ |
||
56 | 'toggle' => 'button', |
||
57 | ], |
||
58 | ], |
||
59 | ]); |
||
60 | } |
||
61 | |||
62 | protected function generateManagementButtons($model) |
||
73 | |||
74 | public function renderSeeNewButton($model) |
||
84 | |||
85 | protected function renderUpdateButton($model) |
||
103 | |||
104 | protected function getRouteForSeeNew() |
||
111 | |||
112 | protected function getRouteForUpdate() |
||
116 | } |
||
117 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.