簡単な質問があります。ヘッダーとフッターを含む1つのデフォルトレイアウトを使用して、作成時に他の.ctpファイルに自動的に表示しようとしていますが、何らかの理由でそれができず、1つのjavascriptファイルを使用して他のすべてのページにも表示します。1 つのデフォルト ファイルのヘッダーとフッターを他のすべてのファイルに表示する方法の例を教えてください。
ご協力ありがとうございました
簡単な質問があります。ヘッダーとフッターを含む1つのデフォルトレイアウトを使用して、作成時に他の.ctpファイルに自動的に表示しようとしていますが、何らかの理由でそれができず、1つのjavascriptファイルを使用して他のすべてのページにも表示します。1 つのデフォルト ファイルのヘッダーとフッターを他のすべてのファイルに表示する方法の例を教えてください。
ご協力ありがとうございました
これが default.ctp の例です
デフォルト.ctp
<html>
<head>
<!--
//here your javascript yourscript.js
//It will be present in all your views.
//the file has to be present in /app/webroot/js
-->
echo $this->Html->script('yourscript');
</head>
<body>
<!--
//header
//the file header.ctp has to be present in /View/Elements
-->
echo $this->element('header');
<!--
//here the content, for example from /View/Posts/edit.ctp
-->
echo $this->fetch('content');
<!--
//footer
//the file footer.ctp has to be present in /View/Elements
-->
echo $this->element('footer');
</body>
</html>
$this->fetch('content') は CakePHP の「魔法」の部分です。ここでビューが取得されます。