1 | <?php |
||
24 | class ListView extends BaseListView |
||
25 | { |
||
26 | /** |
||
27 | * @var array|Closure the HTML attributes for the container of the rendering result of each data model. |
||
28 | * This can be either an array specifying the common HTML attributes for rendering each data item, |
||
29 | * or an anonymous function that returns an array of the HTML attributes. The anonymous function will be |
||
30 | * called once for every data model returned by [[dataProvider]]. |
||
31 | * The "tag" element specifies the tag name of the container element and defaults to "div". |
||
32 | * If "tag" is false, it means no container element will be rendered. |
||
33 | * |
||
34 | * If this property is specified as an anonymous function, it should have the following signature: |
||
35 | * |
||
36 | * ```php |
||
37 | * function ($model, $key, $index, $widget) |
||
38 | * ``` |
||
39 | * |
||
40 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
41 | */ |
||
42 | public $itemOptions = []; |
||
43 | /** |
||
44 | * @var string|callable the name of the view for rendering each data item, or a callback (e.g. an anonymous function) |
||
45 | * for rendering each data item. If it specifies a view name, the following variables will |
||
46 | * be available in the view: |
||
47 | * |
||
48 | * - `$model`: mixed, the data model |
||
49 | * - `$key`: mixed, the key value associated with the data item |
||
50 | * - `$index`: integer, the zero-based index of the data item in the items array returned by [[dataProvider]]. |
||
51 | * - `$widget`: ListView, this widget instance |
||
52 | * |
||
53 | * Note that the view name is resolved into the view file by the current context of the [[view]] object. |
||
54 | * |
||
55 | * If this property is specified as a callback, it should have the following signature: |
||
56 | * |
||
57 | * ```php |
||
58 | * function ($model, $key, $index, $widget) |
||
59 | * ``` |
||
60 | */ |
||
61 | public $itemView; |
||
62 | /** |
||
63 | * @var array additional parameters to be passed to [[itemView]] when it is being rendered. |
||
64 | * This property is used only when [[itemView]] is a string representing a view name. |
||
65 | */ |
||
66 | public $viewParams = []; |
||
67 | /** |
||
68 | * @var string the HTML code to be displayed between any two consecutive items. |
||
69 | */ |
||
70 | public $separator = "\n"; |
||
71 | /** |
||
72 | * @var array the HTML attributes for the container tag of the list view. |
||
73 | * The "tag" element specifies the tag name of the container element and defaults to "div". |
||
74 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
75 | */ |
||
76 | public $options = ['class' => 'list-view']; |
||
77 | /** |
||
78 | * @var Closure an anonymous function that is called once BEFORE rendering each data model. |
||
79 | * It should have the following signature: |
||
80 | * |
||
81 | * ```php |
||
82 | * function ($model, $key, $index, $widget) |
||
83 | * ``` |
||
84 | * |
||
85 | * - `$model`: the current data model being rendered |
||
86 | * - `$key`: the key value associated with the current data model |
||
87 | * - `$index`: the zero-based index of the data model in the model array returned by [[dataProvider]] |
||
88 | * - `$widget`: the ListView object |
||
89 | * |
||
90 | * The return result of the function will be rendered directly. |
||
91 | * Note: If the function returns `null`, nothing will be rendered before the item. |
||
92 | * @see renderBeforeItem |
||
93 | * @since 2.0.11 |
||
94 | */ |
||
95 | public $beforeItem; |
||
96 | /** |
||
97 | * @var Closure an anonymous function that is called once AFTER rendering each data model. |
||
98 | * |
||
99 | * It should have the same signature as [[beforeItem]]. |
||
100 | * |
||
101 | * The return result of the function will be rendered directly. |
||
102 | * Note: If the function returns `null`, nothing will be rendered after the item. |
||
103 | * @see renderAfterItem |
||
104 | * @since 2.0.11 |
||
105 | */ |
||
106 | public $afterItem; |
||
107 | |||
108 | /** |
||
109 | * Renders all data models. |
||
110 | * @return string the rendering result |
||
111 | */ |
||
112 | 9 | public function renderItems() |
|
132 | |||
133 | /** |
||
134 | * Calls [[beforeItem]] closure, returns execution result. |
||
135 | * If [[beforeItem]] is not a closure, `null` will be returned. |
||
136 | * |
||
137 | * @param mixed $model the data model to be rendered |
||
138 | * @param mixed $key the key value associated with the data model |
||
139 | * @param int $index the zero-based index of the data model in the model array returned by [[dataProvider]]. |
||
140 | * @return string|null [[beforeItem]] call result or `null` when [[beforeItem]] is not a closure |
||
141 | * @see beforeItem |
||
142 | * @since 2.0.11 |
||
143 | */ |
||
144 | 8 | protected function renderBeforeItem($model, $key, $index) |
|
152 | |||
153 | /** |
||
154 | * Calls [[afterItem]] closure, returns execution result. |
||
155 | * If [[afterItem]] is not a closure, `null` will be returned. |
||
156 | * |
||
157 | * @param mixed $model the data model to be rendered |
||
158 | * @param mixed $key the key value associated with the data model |
||
159 | * @param int $index the zero-based index of the data model in the model array returned by [[dataProvider]]. |
||
160 | * @return string|null [[afterItem]] call result or `null` when [[afterItem]] is not a closure |
||
161 | * @see afterItem |
||
162 | * @since 2.0.11 |
||
163 | */ |
||
164 | 8 | protected function renderAfterItem($model, $key, $index) |
|
172 | |||
173 | /** |
||
174 | * Renders a single data model. |
||
175 | * @param mixed $model the data model to be rendered |
||
176 | * @param mixed $key the key value associated with the data model |
||
177 | * @param int $index the zero-based index of the data model in the model array returned by [[dataProvider]]. |
||
178 | * @return string the rendering result |
||
179 | */ |
||
180 | 8 | public function renderItem($model, $key, $index) |
|
204 | } |
||
205 |