src/data/Sort.php
public function createSortParam($attribute)
    {
        if (!isset($this->attributes[$attribute])) {
            throw new InvalidConfigException("Unknown attribute: $attribute");
        }
        $definition = $this->attributes[$attribute];
        $directions = $this->getAttributeOrders();
        if (isset($directions[$attribute])) {
            $direction = $directions[$attribute] === SORT_DESC ? SORT_ASC : SORT_DESC;
            unset($directions[$attribute]);
        } else {
            $direction = $definition['default'] ?? SORT_ASC;
        }

        if ($this->enableMultiSort) {
            $directions = array_merge([$attribute => $direction], $directions);
        } else {
            $directions = [$attribute => $direction];
        }

        $sorts = [];
        foreach ($directions as $attribute => $direction) {
            $sorts[] = $direction === SORT_DESC ? '-' . $attribute : $attribute;
        }

        return implode($this->separator, $sorts);
    }
public function createSortParam($attribute)
    {
        if (!isset($this->attributes[$attribute])) {
            throw new InvalidConfigException("Unknown attribute: $attribute");
        }
        $definition = $this->attributes[$attribute];
        $directions = $this->getAttributeOrders();
        if (isset($directions[$attribute])) {
            $direction = $directions[$attribute] === SORT_DESC ? SORT_ASC : SORT_DESC;
            unset($directions[$attribute]);
        } else {
            $direction = $definition['default'] ?? SORT_ASC;
        }

        if ($this->enableMultiSort) {
            $directions = array_merge([$attribute => $direction], $directions);
        } else {
            $directions = [$attribute => $direction];
        }

        $sorts = [];
        foreach ($directions as $attribute => $direction) {
            $sorts[] = $direction === SORT_DESC ? '-' . $attribute : $attribute;
        }

        return implode($this->separator, $sorts);
    }
public function createSortParam ( $ attribute ) { if ( ! isset ( $ this -> attributes [ $ attribute ] ) ) { throw new InvalidConfigException ( "Unknown attribute: $attribute" ) ; } $ definition = $ this -> attributes [ $ attribute ] ; $ directions = $ this -> getAttributeOrders ( ) ; if ( isset ( $ directions [ $ attribute ] ) ) { $ direction = $ directions [ $ attribute ] === SORT_DESC ? SORT_ASC : SORT_DESC ; unset ( $ directions [ $ attribute ] ) ; } else { $ direction = $ definition [ 'default' ] ?? SORT_ASC ; } if ( $ this -> enableMultiSort ) { $ directions = array_merge ( [ $ attribute => $ direction ] , $ directions ) ; } else { $ directions = [ $ attribute => $ direction ] ; } $ sorts = [ ] ; foreach ( $ directions as $ attribute => $ direction ) { $ sorts [ ] = $ direction === SORT_DESC ? '-' . $ attribute : $ attribute ; } return implode ( $ this -> separator , $ sorts ) ; }
Creates the sort variable for the specified attribute.
The newly created sort variable can be used to create a URL that will lead to
sorting by the specified attribute.
@param string $attribute the attribute name
@return string the value of the sort variable
@throws InvalidConfigException if the specified attribute is not defined in [[attributes]]
Creates the sort variable for the specified attribute . The newly created sort variable can be used to create a URL that will lead to sorting by the specified attribute .