PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 16, 2022

[FIXED] cakephp: Order index by ID desc after ADD

 January 16, 2022     cakephp, cakephp-3.x, php     No comments   

Issue

In my application, all index views are sorted by name ASC, by default. I need to order data by ID desc, only after adding a new row, to help the user see the last added row in top of the index.

in controller, add function:

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

This try did not work:

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

what should I do ?


Solution

do you have pagination enabled for your views?

if so the correct link should be

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


Answered By - arilia
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing