CakePHP3.3.4でViewの内容をTemplate(index.ctp)を使わずにController側で動的に生成して表示する方法を模索しております。
php
1class IndexController extends AppController { 2 3 public function test() { 4 $layout_source="<body><?= $this->fetch('content') ?></body>" 5 $template_source="<div>HelloWord</div>"; 6 } 7}
上記のようなContorollerの場合、通常は
「src/Template/Layout/default.ctp」
「src/Template/Index/test.ctp」
を使ってCakePHP側で自動的に出力してくれると思いますが期待している結果としては、
「src/Template/Layout/default.ctp」
「src/Template/Index/test.ctp」を使わずにContoroller側で指定した$layout_sourceと$template_sourceを使用してレンダーしたいというものです。
「src/Template/Layout/default.ctp」の代わりに$layout_source
「src/Template/Index/test.ctp」の代わりにtemplate_source
このような方法を実現する方法を調べたのですが見つけることができませんでしたのでぜひ皆様のお知恵をお貸しいただければと思います。
どぞよろしくお願いいたします。