简体   繁体   中英

How to link a custom CSS file in CakePHP2

How can I link a custom CSS file to my view in CakePHP2? I have a page that needs a unique css style and would like to know how to connect a custom stylesheet.

I've looked for an answer to this question and couldn't find one. I figured out the answer by searching my codebase, I'm just putting this here to help others.

The best way I've found to do this is by creating an array of css file names in the controller, then using the form creator in the view.

This goes in your controller:

$this->set('cssIncludes' => array('CSSFileName'));

This goes in your view:

if (isset($cssIncludes)) echo $this->Html->css($cssIncludes);

The CSS file goes in webroot/css/CSSFileName.css

This format allows you to specify multiple css files with minimal effort. It's also fairly robust.

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.

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