src/Template/Layout/default.ctp
なるほど、これは便利ですね。
<?php /** * CakePHP(tm) : Rapid Development Framework (https://cakephp.org) * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) * * Licensed under The MIT License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) * @link https://cakephp.org CakePHP(tm) Project * @since 0.10.0 * @license https://opensource.org/licenses/mit-license.php MIT License */ $cakeDescription = 'CakePHP: the rapid development php framework'; ?> <!DOCTYPE html> <html> <head> <?= $this->Html->charset() ?> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title> <?= $cakeDescription ?>: <?= $this->fetch('title') ?> </title> <?= $this->Html->meta('icon') ?> <?= $this->Html->css('base.css') ?> <?= $this->Html->css('cake.css') ?> <?= $this->fetch('meta') ?> <?= $this->fetch('css') ?> <?= $this->fetch('script') ?> </head> <body> <nav class="top-bar expanded" data-topbar role="navigation"> <ul class="title-area large-3 medium-4 columns"> <li class="name"> <h1><a href=""><?= $this->fetch('title') ?></a></h1> </li> </ul> <div class="top-bar-section"> <ul class="right"> <li><a target="_blank" href="https://book.cakephp.org/3.0/">Documentation</a></li> <li><a target="_blank" href="https://api.cakephp.org/3.0/">API</a></li> </ul> </div> </nav> <?= $this->Flash->render() ?> <div class="container clearfix"> <?= $this->fetch('content') ?> </div> <footer> </footer> </body> </html>
レイアウトをカスタマイズします。
src/Template/my_layou.ctp
<!DOCTYPE html> <html> <head> <?= $this->Html->charset() ?> <title> <?= $this->fetch('title') ?> </title> <?= $this->Html->css('styles.css') ?> </head> <body> <section class="container"> <?= $this->fetch('content') ?> </section> </body> </html>
controllerでレイアウトを指定します。
PostsController.php
<?php namespace App\Controller; class PostsController extends AppController { public function index() { $this->viewBuilder()->layout('my_layout'); $posts = $this->Posts->find('all'); $this->set('posts', $posts); } }
なるほど、すこし見えてきましたね。