テンプレート
src/Template/Hello/index.ctpを作ってテンプレートを以下のように用意
<!DOCTYPE html> <html lang="ja"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Hello Page</title> </head> <body> <h1>midashi</h1> <p> hello hello </p> </body> </html>
コントローラ側でautoRenderをtrueにしてテンプレートを読み込む。
<?php namespace App\Controller; class HelloController extends AppController { public $name = "Hello"; public $autoRender = true; public function index() { $this->viewBuilder()->autoLayout(false); } } ?>
自動レイアウト(autoLayout)はなしにした。
テンプレート名を変えればその名前のアクションに適用される。
自動レイアウトを使用する場合はテンプレートは
<h1>midashi</h1> <p> hello hello </p>
のみで良く。コントローラの方は $this->viewBuilder()->autoLayout(false);の行を削る。
これでデフォルトのレイアウト(src/Template/Layout/default.ctp)が適応される。