[英]how to convert an HTML template into Cake PHP template
我是蛋糕 php 的初學者。 我需要將我的 HTML 模板轉換為 Cake PHP 模板。 任何想法?
這很容易。
index.html
到index.ctp
通常大多數模板設置如下:
<html> <head> <title>My Site</title> // You will include your javascript and css files here <?php echo $this->Html->css(array('cake.generic','default')); echo $this->Html->script(array('myscript','jquery')); ?> </head> <body> <div id="container"> <div id="header"></div> <div id="body"> <div id="main_content" style="width:600px;float:left"> <?php //Code for this should be in your home.ctp // in your pages folder. Usually I cut this content from // my template and place the whole thing in that file // everything else happens magically echo $content_for_layout; ?> </div> <div id="side_content" style="width:300px;float:left"> <?-- You can have content here manually or create elements and include them here like the following --> <;php $this->element("sidebar_content")? .> </div> </div> <div id="footer">...</div> </div> </body>
然后,您應該將所有圖像上傳到/app/webroot
文件夾中的/img
文件夾
將圖像路徑更改為引用/img
文件夾。
您必須對所有 CSS 和 JS 文件執行相同操作。 將它們放在/app/webroot
位置的相應文件夾中。
祝你好運!
將您的模板保存到APP/views/layouts/template.ctp
。
確保它至少有兩個變量:
<title><?php echo $title_for_layout; ?></title>
和
<body>
<?php echo $content_for_layout; ?>
</body>
啟動您的視圖,或 controller 並添加$this->layout = 'template'; // view/method
$this->layout = 'template'; // view/method
或$layout = 'template'; // controller;
$layout = 'template'; // controller;
查看 Cake default.ctp
以獲取想法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.