I'm a beginner in cake php. i have needed to convert my HTML template into 开发者_开发技巧Cake PHP template. any idea?
It is very easy.
- Replace your template main file extension to .ctp
index.html
toindex.ctp
- Look at the layout of you file (html code) and determine what section of that template you want to appear on all pages;
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>
You should then upload all images to the
/img
folder in your/app/webroot
folderChange your images path to reference
/img
folder.You must do the same with all your CSS and JS files. Place them in their corresponding folders in the
/app/webroot
location.
Good luck!
Save your template in to 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
or $layout = 'template'; // controller;
Look at the Cake default.ctp
for ideas.
精彩评论