public function __construct($id, $controller, $config = []) { parent::__construct($id, $controller, $config); if (is_array($this->sort) && !isset($this->sort["class"])) { $this->sort["class"] = Sort::className(); $this->sort = \Yii::createObject($this->sort); } if ($this->sort == null) { $this->sort = \Yii::createObject(Sort::className()); } if ($this->searchModelClass == null && class_exists($this->modelClass . "Search")) { $this->searchModelClass = $this->modelClass . "Search"; } }
/** * @inheritdoc */ public function setSort($value) { if (is_array($value)) { $config = ['class' => Sort::className(), 'enableMultiSort' => $this->enableMultiSort]; $this->_sort = Yii::createObject(array_merge($config, $value)); } elseif ($value instanceof Sort || $value === false) { $this->_sort = $value; } else { throw new InvalidParamException('Only Sort instance, configuration array or false is allowed.'); } if (($sort = $this->getSort()) !== false && $this->query instanceof ActiveQueryInterface) { /* @var $model Model */ $model = new $this->query->modelClass(); if (empty($sort->attributes)) { foreach ($model->attributes() as $attribute) { $sort->attributes[$attribute] = ['asc' => [$attribute => SORT_ASC], 'desc' => [$attribute => SORT_DESC], 'label' => $model->getAttributeLabel($attribute)]; } } else { foreach ($sort->attributes as $attribute => $config) { if (!isset($config['label'])) { $sort->attributes[$attribute]['label'] = $model->getAttributeLabel($attribute); } } } } }
/** * Sets the sort definition for this data provider. * @param array|Sort|boolean $value the sort definition to be used by this data provider. * This can be one of the following: * * - a configuration array for creating the sort definition object. The "class" element defaults * to 'yii\data\Sort' * - an instance of [[Sort]] or its subclass * - false, if sorting needs to be disabled. * * @throws InvalidParamException */ public function setSort($value) { if (is_array($value)) { $config = ['class' => Sort::className()]; if ($this->id !== null) { $config['sortVar'] = $this->id . '-sort'; } $this->_sort = Yii::createObject(array_merge($config, $value)); } elseif ($value instanceof Sort || $value === false) { $this->_sort = $value; } else { throw new InvalidParamException('Only Sort instance, configuration array or false is allowed.'); } }
/** * Имя класса сортировки * @return string */ public function sortClassName() { return Sort::className(); }