0

首先,我正在学习yii2。

我想通过添加“desc”“sort”(降序排序)重定向到特定的 URL 我有一个包含 4 列的网格视图。

我想通过在 URL 中默认添加排序来重定向。

我添加了网址

return $this->redirect(array('city/index','UserCitySearch[citytype]' => 54));

我需要在上面的重定向中按顺序sorting添加"added_time"descending

任何人都可以帮助我如何在重定向 url 中添加这种排序。

4

1 回答 1

1

这取决于您用于排序的组件及其配置方式。

如果您使用yii\data\Sort带默认值的标准,则需要设置的参数是sort,并且降序是通过在列名前加上-.

return $this->redirect(array(
    'city/index',
    'UserCitySearch[citytype]' => 54,
    'sort' => '-added_time',
));

参数名称取决于yii\data\Sort::$sortParam属性。

于 2020-04-29T05:50:22.170 回答