CodeIgniter + CSS

Voj*_*ech 7 css codeigniter codeigniter-2

美好的一天,我正在和Smarty一起学习CodeIgniter.我的CSS文件存储在

/App01/application/views/css/main.css
Run Code Online (Sandbox Code Playgroud)

要链接我的CSS,我使用:

<link rel="stylesheet" type="text/css" href="http://localhost:88/APP1/application/views/css/layout.css" media="screen" />
Run Code Online (Sandbox Code Playgroud)

但是我的页面上没有应用CSS.当我打开CSS URL时,我收到一条消息:

Forbidden
You don't have permission to access /APP1/application/views/css/layout.css on this server.
Run Code Online (Sandbox Code Playgroud)

拜托,我做错了什么?我想将CSS与视图保持在一起,因为将来我想学习如何创建多个主题,我认为CSS应该保存在主题文件夹中.

我可以用一些Smarty变量替换CSS文件的URL路径,这样当我移动我的应用程序时,我不需要手动更改模板中的CSS URL路径吗?

先感谢您!Vojtech

Tho*_*rds 13

/applicationCodeIgniter文件夹中的任何内容都应被视为越界.为了获得最佳安全性,您应该考虑在以下结构中保留/application您的wwwpublic_html文件夹:

– application
    – controllers
    – models
    – views
    – ...
– system
    – core
    – libraries
    – ...
– public_html
    – index.php
Run Code Online (Sandbox Code Playgroud)

这使您的应用程序代码更安全.

我建议在公共文件夹中创建客户端脚本和CSS.例如public_html/csspublic_html/js.或者,如果你想沿着主题路线走下去,可能会将每个CSS文件命名为主题的名称,所以你有css/theme1.csscss/theme2.css.

如果您的网站始终使用域的根目录,那么您可以使用:

<link rel="stylesheet" type="text/css" href="/css/layout.css" media="screen" />
Run Code Online (Sandbox Code Playgroud)

但是如果你觉得你将要移动各种各样的东西,那么考虑在控制器中准备文件位置,然后再发送给Smarty.

$this->load->helper('url');
$this->smarty->assign('css_file', base_url("css/theme1.css"));
Run Code Online (Sandbox Code Playgroud)

那会回来:

http://localhost/app1/css/theme.css
Run Code Online (Sandbox Code Playgroud)

或者您的CodeIgniter URL是什么.