|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
-
-
- namespace yii\widgets;
-
- use Yii;
- use yii\base\InvalidConfigException;
- use yii\base\Widget;
- use yii\data\Sort;
- use yii\helpers\Html;
-
-
- class LinkSorter extends Widget
- {
-
-
- public $sort;
-
-
- public $attributes;
-
-
- public $options = ['class' => 'sorter'];
-
-
- public $linkOptions = [];
-
-
-
-
- public function init()
- {
- if ($this->sort === null) {
- throw new InvalidConfigException('The "sort" property must be set.');
- }
- }
-
-
-
- public function run()
- {
- echo $this->renderSortLinks();
- }
-
-
-
- protected function renderSortLinks()
- {
- $attributes = empty($this->attributes) ? array_keys($this->sort->attributes) : $this->attributes;
- $links = [];
- foreach ($attributes as $name) {
- $links[] = $this->sort->link($name, $this->linkOptions);
- }
-
- return Html::ul($links, array_merge($this->options, ['encode' => false]));
- }
- }
|