* @since 2.0 */ abstract class ListViewBase extends Widget { /** * @var array the HTML attributes for the container tag of the list view. * The "tag" element specifies the tag name of the container element and defaults to "div". */ public $options = array(); /** * @var \yii\data\DataProviderInterface the data provider for the view. This property is required. */ public $dataProvider; /** * @var array the configuration for the pager widget. By default, [[LinkPager]] will be * used to render the pager. You can use a different widget class by configuring the "class" element. */ public $pager = array(); /** * @var array the configuration for the sorter widget. By default, [[LinkSorter]] will be * used to render the sorter. You can use a different widget class by configuring the "class" element. */ public $sorter = array(); /** * @var string the HTML content to be displayed as the summary of the list view. * If you do not want to show the summary, you may set it with an empty string. * * The following tokens will be replaced with the corresponding values: * * - `{begin}`: the starting row number (1-based) currently being displayed * - `{end}`: the ending row number (1-based) currently being displayed * - `{count}`: the number of rows currently being displayed * - `{totalCount}`: the total number of rows available * - `{page}`: the page number (1-based) current being displayed * - `{pageCount}`: the number of pages available */ public $summary; /** * @var string|boolean the HTML content to be displayed when [[dataProvider]] does not have any data. * If false, the list view will still be displayed (without body content though). */ public $empty; /** * @var string the layout that determines how different sections of the list view should be organized. * The following tokens will be replaced with the corresponding section contents: * * - `{summary}`: the summary section. See [[renderSummary()]]. * - `{items}`: the list items. See [[renderItems()]]. * - `{sorter}`: the sorter. See [[renderSorter()]]. * - `{pager}`: the pager. See [[renderPager()]]. */ public $layout = "{summary}\n{items}\n{pager}"; /** * Renders the data models. * @return string the rendering result. */ abstract public function renderItems(); /** * Initializes the view. */ public function init() { if ($this->dataProvider === null) { throw new InvalidConfigException('The "dataProvider" property must be set.'); } } /** * Runs the widget. */ public function run() { if ($this->dataProvider->getCount() > 0 || $this->empty === false) { $widget = $this; $content = preg_replace_callback("/{\\w+}/", function ($matches) use ($widget) { $content = $widget->renderSection($matches[0]); return $content === false ? $matches[0] : $content; }, $this->layout); } else { $content = '