簡體   English   中英

如何將 HTML 模板轉換為 Cake PHP 模板

[英]how to convert an HTML template into Cake PHP template

我是蛋糕 php 的初學者。 我需要將我的 HTML 模板轉換為 Cake PHP 模板。 任何想法?

這很容易。

  1. 將您的模板主文件擴展名替換為 .ctp
  2. index.htmlindex.ctp
  3. 查看文件的布局(html 代碼)並確定要在所有頁面上顯示該模板的哪個部分;
  4. 通常大多數模板設置如下:

     <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>

  5. 然后,您應該將所有圖像上傳到/app/webroot文件夾中的/img文件夾

  6. 將圖像路徑更改為引用/img文件夾。

  7. 您必須對所有 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM