123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?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()
- {
- parent::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]));
- }
- }
|