简体   繁体   English

如何将 HTML 模板转换为 Cake PHP 模板

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

I'm a beginner in cake php.我是蛋糕 php 的初学者。 i have needed to convert my HTML template into Cake PHP template.我需要将我的 HTML 模板转换为 Cake PHP 模板。 any idea?任何想法?

It is very easy.这很容易。

  1. Replace your template main file extension to.ctp将您的模板主文件扩展名替换为 .ctp
  2. index.html to index.ctp index.htmlindex.ctp
  3. Look at the layout of you file (html code) and determine what section of that template you want to appear on all pages;查看文件的布局(html 代码)并确定要在所有页面上显示该模板的哪个部分;
  4. Usually most templates are setup as follows:通常大多数模板设置如下:

     <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. You should then upload all images to the /img folder in your /app/webroot folder然后,您应该将所有图像上传到/app/webroot文件夹中的/img文件夹

  6. Change your images path to reference /img folder.将图像路径更改为引用/img文件夹。

  7. You must do the same with all your CSS and JS files.您必须对所有 CSS 和 JS 文件执行相同操作。 Place them in their corresponding folders in the /app/webroot location.将它们放在/app/webroot位置的相应文件夹中。

Good luck!祝你好运!

Save your template in to APP/views/layouts/template.ctp .将您的模板保存到APP/views/layouts/template.ctp

Make sure it has at least two variables:确保它至少有两个变量:

<title><?php echo $title_for_layout; ?></title>

and

<body>
    <?php echo $content_for_layout; ?>
</body>

Fire up your view, or controller and add $this->layout = 'template'; // view/method启动您的视图,或 controller 并添加$this->layout = 'template'; // view/method $this->layout = 'template'; // view/method or $layout = 'template'; // controller; $this->layout = 'template'; // view/method$layout = 'template'; // controller; $layout = 'template'; // controller;

Look at the Cake default.ctp for ideas.查看 Cake default.ctp以获取想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM