LoginSignup
3
6

More than 5 years have passed since last update.

CakePHP3:デフォルトのソート順を指定しつつ、ユーザの指定を尊重する

Posted at
ArticlesController.php

  if( null !== $this->request->query("sort") ){
    // ユーザがsort順を指定している
    $query = $this->Articles;
  }else{
    // デフォルトで、idの降順でソート
   $query = $this->Articles->find()->order(['id' => 'DESC']);
  }

  $articles = $this->paginate($query);
3
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
6