【问题标题】:How to link a custom CSS file in CakePHP2How to link a custom CSS file in CakePHP2
【发布时间】:2022-12-02 01:43:36
【问题描述】:

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.

【问题讨论】:

    标签: php css cakephp cakephp-2.0


    【解决方案1】:

    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.

    【讨论】:

      猜你喜欢
      • 2022-12-01
      • 2022-12-01
      • 2022-12-27
      • 2022-12-01
      • 2022-12-26
      • 2022-12-26
      • 2022-08-27
      • 2022-12-02
      • 2022-12-02
      相关资源
      最近更新 更多