Wednesday, June 24, 2009

Getting CSS to work from your layout files in Cakephp

If you want your handwritten css files to work in your cakephp application, remember that you have to use the echo statement. Ok, here i go step by step.

Once you finish designing the structure of your application, you go on to bake it (i.e use the bake script to generate basic add/delete/view functionalities).
Having done that, your application performs its basic tasks and then you go on to tweak it.

When you finally head over to doing the front end design, you should create your css files, and your images/icons first. Then head over to the layouts folder and create the layouts you want. Layouts are common templates within which the action specific views will load. When you do this, you would like to insert links to your css files in the head tag of your layout page.For this, use $html->css(' <filename> '); where your css file is filename.css and remember to echo it.
It should finally look like this :-
<head>
<?php echo $html->css('somename'); ?> // where somename.css is my css file

Read this article for explanations on the same topic.