参考にさせて頂いたページ
レイアウトを作ろう!(1/4):初心者のためのCakePHP2.0 プログラミング入門
レイアウトファイルの作成
参考ページにならってLayoutsディレクトリにSample.ctpを作成した。
もともと用意されているdefault.ctpとかをコピーして作成した。
SampleController.phpの記述内容
参考ページにならって以下のとおり。(indexアクションの部分だけ)
public function index() {
$this->modelClass = null;
$this->layout = "Sample";
$this->set("header_for_layout","Sample Application");
$this->set("footer_for_layout",
"copyright by SYODA-Tuyano. 2011.");
$this->set("msg", "Welcome to my layout!");
}
View/Sample/index.ctpの記述内容
参考ページにならって以下のとおり
<h1>Index Page</h1>
<p>this is test View.</p>
<p><?php echo $msg; ?></p>
まとめ
$this->layout = "Sample";
みたいな感じでControllerファイルに書いて、Layouts/Sample.ctpを読み込む。
明示的に指定しない場合はdefault.ctpが読み込まれる。
Layoutに関してはなんとなくわかるのでこのくらいで次へ進む。