yii\data\Sort::getAttributeOrder PHP Method

getAttributeOrder() public method

Returns the sort direction of the specified attribute in the current request.
public getAttributeOrder ( string $attribute ) : boolean | null
$attribute string the attribute name
return boolean | null Sort direction of the attribute. Can be either `SORT_ASC` for ascending order or `SORT_DESC` for descending order. Null is returned if the attribute is invalid or does not need to be sorted.
    public function getAttributeOrder($attribute)
    {
        $orders = $this->getAttributeOrders();
        return isset($orders[$attribute]) ? $orders[$attribute] : null;
    }

Usage Example

示例#1
0
 public function testGetAttributeOrder()
 {
     $sort = new Sort(['attributes' => ['age', 'name' => ['asc' => ['first_name' => SORT_ASC, 'last_name' => SORT_ASC], 'desc' => ['first_name' => SORT_DESC, 'last_name' => SORT_DESC]]], 'params' => ['sort' => 'age,-name'], 'enableMultiSort' => true]);
     $this->assertEquals(SORT_ASC, $sort->getAttributeOrder('age'));
     $this->assertEquals(SORT_DESC, $sort->getAttributeOrder('name'));
     $this->assertNull($sort->getAttributeOrder('xyz'));
 }
All Usage Examples Of yii\data\Sort::getAttributeOrder