yii\data\Sort::setAttributeOrders PHP Method

setAttributeOrders() public method

Sets up the currently sort information.
Since: 2.0.10
public setAttributeOrders ( array | null $attributeOrders, boolean $validate = true )
$attributeOrders array | null sort directions indexed by attribute names. Sort direction can be either `SORT_ASC` for ascending order or `SORT_DESC` for descending order.
$validate boolean whether to validate given attribute orders against [[attributes]] and [[enableMultiSort]]. If validation is enabled incorrect entries will be removed.
    public function setAttributeOrders($attributeOrders, $validate = true)
    {
        if ($attributeOrders === null || !$validate) {
            $this->_attributeOrders = $attributeOrders;
        } else {
            $this->_attributeOrders = [];
            foreach ($attributeOrders as $attribute => $order) {
                if (isset($this->attributes[$attribute])) {
                    $this->_attributeOrders[$attribute] = $order;
                    if (!$this->enableMultiSort) {
                        break;
                    }
                }
            }
        }
    }