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 | * @see renderBeforeItem |
||
92 | * @since 2.0.11 |
||
93 | */ |
||
94 | public $beforeItem; |
||
95 | /** |
||
96 | * @var Closure an anonymous function that is called once AFTER rendering each data model. |
||
97 | * It should have the similar signature as [[beforeItem]]. The return result of the function |
||
98 | * will be rendered directly. |
||
99 | * @see renderAfterItem |
||
100 | * @since 2.0.11 |
||
101 | */ |
||
102 | public $afterItem; |
||
103 | |||
104 | /** |
||
105 | * Renders all data models. |
||
106 | * @return string the rendering result |
||
107 | */ |
||
108 | 9 | public function renderItems() |
|
128 | |||
129 | /** |
||
130 | * Calls [[beforeItem]] closure, returns execution result. |
||
131 | * If [[beforeItem]] is not a closure, `null` will be returned. |
||
132 | * |
||
133 | * @param mixed $model the data model to be rendered |
||
134 | * @param mixed $key the key value associated with the data model |
||
135 | * @param int $index the zero-based index of the data model in the model array returned by [[dataProvider]]. |
||
136 | * @return string|null [[beforeItem]] call result or `null` when [[beforeItem]] is not a closure |
||
137 | * @see beforeItem |
||
138 | * @since 2.0.11 |
||
139 | */ |
||
140 | 8 | protected function renderBeforeItem($model, $key, $index) |
|
148 | |||
149 | /** |
||
150 | * Calls [[afterItem]] closure, returns execution result. |
||
151 | * If [[afterItem]] is not a closure, `null` will be returned. |
||
152 | * |
||
153 | * @param mixed $model the data model to be rendered |
||
154 | * @param mixed $key the key value associated with the data model |
||
155 | * @param int $index the zero-based index of the data model in the model array returned by [[dataProvider]]. |
||
156 | * @return string|null [[afterItem]] call result or `null` when [[afterItem]] is not a closure |
||
157 | * @see afterItem |
||
158 | * @since 2.0.11 |
||
159 | */ |
||
160 | 8 | protected function renderAfterItem($model, $key, $index) |
|
168 | |||
169 | /** |
||
170 | * Renders a single data model. |
||
171 | * @param mixed $model the data model to be rendered |
||
172 | * @param mixed $key the key value associated with the data model |
||
173 | * @param int $index the zero-based index of the data model in the model array returned by [[dataProvider]]. |
||
174 | * @return string the rendering result |
||
175 | */ |
||
176 | 8 | public function renderItem($model, $key, $index) |
|
200 | } |
||
201 |