I’m trying to undestand how to link CSS or JS I’ll use it all over my CakePHP 1.3 application. I’ve read about putting assets in folder /app/webroot/css or /app/layouts/css (for css only in this case).
I’ve put a file named main.css and default.css but I’m missing something.
How can I do to fix it and which are the default rules for the default layout?
Normal
$this->Html->css('my_file');corresponds to/app/webroot/css/my_file.css$this->Html->script('my_file');corresponds to/app/webroot/js/my_file.jsyou add the php part from above to your layout file which is by default in
/app/views/layouts/default.ctp(or in cake dir if you have not created one)you can set the layout in the controller/app_controller setting
$this->layout = 'foo';which points to/app/views/layouts/foo.ctpThemes
Setting the controller to
$this->view = 'Theme';will make cake use themes then setting$this->theme = 'SomeTheme';in the controller will make cake use/app/views/themed/some_theme/*filesusing
$this->Html->script('my_file');now points to/app/views/themed/some_theme/js/my_file.jsand the same goes for the css.css = http://book.cakephp.org/view/1437/css
js = http://book.cakephp.org/view/1589/script
themes = http://book.cakephp.org/view/1093/Themes
themes have the problem of serving css, js and other assets through php (ob_start(); include etc) and this is obviously slower than normal http serving. you can either copy files across to the webroot folder as explained in the bottom or be lazy and do something like the following https://gist.github.com/712622