【问题标题】:cakephp: Order index by ID desc after ADDcakephp:添加后按 ID desc 排序索引
【发布时间】:2018-07-09 14:46:16
【问题描述】:

在我的应用程序中,默认情况下,所有索引视图都按名称 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']]);

我该怎么办?

【问题讨论】:

    标签: php cakephp cakephp-3.x


    【解决方案1】:

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

    如果是这样,正确的链接应该是

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

    【讨论】:

      猜你喜欢
      • 2023-04-06
      • 2023-03-13
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      • 2016-02-15
      • 2016-06-07
      • 1970-01-01
      • 2011-07-04
      相关资源
      最近更新 更多