doumo0206 2011-07-08 17:03
浏览 25
已采纳

如何使用MVC代码点火器项目动态控制静态CSS文件中的路径

I'm creating a website/codeigniter-project that uses views which link to external CSS files.

Everywhere throughout my project/web-page's views I can control the URL paths of images, links, etc by constructing them from the 'base_url' setting variable. I don't have any control over static, linked external CSS files. This means that whenever my base URL path changes for my site I have to go through my CSS files and do global search/replaces to update all my paths.

To solve this I thought about creating a controller just to load CSS/JavaScript files and treating the actual files like views with hooks but I was talked out of this by @WesleyMurch in this question:

Using a controller to handle returning customized css & javascript files with codeigniter

How can I dynamically assign base-paths to my css assets so I don't have to do global search and replaces every time I update the base path of my site?

  • 写回答

1条回答 默认 最新

  • dongyu6276 2011-07-08 17:12
    关注

    For this I use a view file containing css code with all the variables. The only change is that you should set appropriate headers for CSS

    Create function style in your controller and set it to render appropriate view file (style.php). Code all your css with php code in style.php.

    Set following headers at the start of the function:

    header("ContentType: text/css");
    header("Expires: <some far future expiration time or use mod_expires with apache>");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计