なぜかroutingの設定は好きですね。
app/config/routes.php
Router::scope('/', function (RouteBuilder $routes) { /** * Here, we are connecting '/' (base path) to a controller called 'Pages', * its action called 'display', and we pass a param to select the view file * to use (in this case, src/Template/Pages/home.ctp)... */ // $routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']); $routes->connect('/', ['controller' => 'Posts', 'action' => 'index']);
actionがなぜindexなのでしょう???
controllerのsqlのorder byは以下のように書くようです。
$posts = $this->Posts->find('all')->order(['title' => 'DESC']);
SELECT * FROM posts LIMIT 10;は
$posts = $this->Posts->find('all')->limit(2);
ですね。
<?php // /post/index // /(controller)/(action)/(options) namespace App\Controller; class PostsController extends AppController { public function index() { // modelからデータを取得し、postsに入れる $posts = $this->Posts->find('all')->order(['title' => 'DESC']) ->limit(2) ->where(['title like' => '%3']); $this->set('posts', $posts); } ?>