cakephp:添加后按 ID desc 排序索引

cakephp: Order index by ID desc after ADD

在我的应用程序中,所有索引视图默认按名称 ASC 排序。 我需要按 ID desc 对数据进行排序,仅在添加新行后,以帮助用户查看索引顶部最后添加的行。

在控制器中,添加功能:

if ($this->Assets->save($asset)) {
            $this->Flash->success(__('The asset has been saved.'));
            //die('new id:' . $asset->id);
            return $this->redirect(['action' => 'index']);
        }

这个尝试没有成功:

return $this->redirect(['action' => 'index', 'order' => ['id' => 'DESC']]);

我该怎么办?

您是否为您的视图启用了分页?

如果是这样,正确的 link 应该是

return $this->redirect([
    'action' => 'index', 
    '?' => [
        'sort' => 'id',
        'direction' => 'desc'
    ]
]);