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.
index.html
to index.ctp
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
folder
Change 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
$this->layout = 'template'; // view/method
or $layout = 'template'; // controller;
$layout = 'template'; // controller;
Look at the Cake default.ctp
for ideas.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.