美好的一天,我正在通过 Smarty 学习 CodeIgniter。我的 CSS 文件存储在
/App01/application/views/css/main.css
要链接我的 CSS,我使用:
<link rel="stylesheet" type="text/css" href="http://localhost:88/APP1/application/views/css/layout.css" media="screen" />
但是我的页面上没有应用 CSS。当我打开 CSS URL 时,我收到一条消息:
Forbidden
You don't have permission to access /APP1/application/views/css/layout.css on this server.
拜托,我做错了什么?我想将我的 CSS 与 View 放在一起,因为将来我想学习如何创建多个主题,我认为 CSS 应该保存在主题文件夹中。
我能否用一些 Smarty 变量替换 CSS 文件的 URL 路径,这样当我移动我的应用程序时,我不需要手动更改模板中的 CSS URL 路径?
提前致谢!沃伊科技
最佳答案
CodeIgniter 的 /application
文件夹中的任何内容都应被视为越界。为了获得最佳安全性,您实际上应该考虑将 /application
保持在您的 www
或 public_html
文件夹之上,结构如下:
– application
– controllers
– models
– views
– ...
– system
– core
– libraries
– ...
– public_html
– index.php
这使您的应用程序代码更安全。
我建议在公共(public)文件夹中创建客户端脚本和 CSS。例如 public_html/css
和 public_html/js
。或者,如果你想走主题路线,可能将每个 CSS 文件命名为主题名称,这样你就有了 css/theme1.css
和 css/theme2.css
。
如果您的站点始终从域的根目录运行,那么您可以使用:
<link rel="stylesheet" type="text/css" href="/css/layout.css" media="screen" />
但是如果你觉得你要移动各种各样的东西,那么考虑在将它发送到 Smarty 之前在你的 Controller 中准备好文件位置。
$this->load->helper('url');
$this->smarty->assign('css_file', base_url("css/theme1.css"));
这将返回:
http://localhost/app1/css/theme.css
或者您的 CodeIgniter URL 是什么。
关于css - 代码点火器 + CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8848297/