我正在创建一个网站/codeigniter-项目,它使用链接到外部 CSS 文件的视图。
在我的项目/网页视图中的任何地方,我都可以通过从“base_url”设置变量构建图像、链接等来控制它们的 URL 路径。我对静态、链接的外部 CSS 文件没有任何控制权。这意味着每当我的网站的基本 URL 路径发生更改时,我都必须浏览 CSS 文件并执行全局搜索/替换以更新我的所有路径。
为了解决这个问题,我考虑创建一个控制器来加载 CSS/JavaScript 文件,并将实际文件处理为带有钩子的视图,但 @WesleyMurch 在这个问题中对此进行了讨论:
使用控制器处理返回的自定义 css &使用 codeigniter 的 javascript 文件
如何动态地将基本路径分配给我的 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)
为此,我使用包含 css 代码和所有变量的视图文件。唯一的变化是您应该
在控制器中为 CSS Create
function style
设置适当的标头,并将其设置为呈现适当的视图文件 (style.php
)。在style.php
中使用 php 代码编写所有 css。在函数的开头设置以下标头:
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 instyle.php
.Set following headers at the start of the function: