public $autoRender = false; を外すとviewテンプレートが使える様になる
view templateとlayoutがある
layoutにビューテンプレートをはめ込む
src/Template/Hello/index.ctp
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello</title>
<style>
h1 {
font-size: 60pt;
margin: 0px 0px 10px 0px; padding: 0px 20px; color: white;
background: linear-gradient(to right, #aaa, #fff);
}
p { font-size: 14pt; color: #666; }
</style>
</head>
<body>
<header class="row">
<h1><?=$title ?></h1>
</header>
<div class="row">
<p><?=$message ?></p>
</div>
</body>
</html>
HelloController.php
class HelloController extends AppController {
public function index(){
$this->viewBuilder()->autoLayout(false);
$this->set('title', 'Hello!');
$this->set('message', 'This is message!');
}
}
配列で渡す場合
public function index(){
$this->viewBuilder()->autoLayout(false);
$values = [
'title' => "hello!",
"message" => "this is message!!!"
];
$this->set($values);
}
autoLayout(false);で自動レイアウトをoffにしている
OK, controllerとviewの関係性はなんとなく分かったぞ!
