There is no need to write code for it. Yii already supports inverse sorting by adding a negative sign to attribute name as shown here [Yii core code].
Unless name is not included in your model's safe attributes list, you can just use sort=-name instead of sort=name desc :
…