代码点火器 + CSS
美好的一天,我正在用 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 与视图放在一起,因为将来我想学习如何创建多个主题,并且我认为 CSS 应该保存在主题文件夹中。
我可以用一些 Smarty 变量替换 CSS 文件的 URL 路径,这样当我移动应用程序时,我不需要手动更改模板中的 CSS URL 路径吗?
先感谢您!沃伊泰克
Good Day, I'm learning CodeIgniter with Smarty. My CSS file is stored in
/App01/application/views/css/main.css
To link my CSS I use:
<link rel="stylesheet" type="text/css" href="http://localhost:88/APP1/application/views/css/layout.css" media="screen" />
But CSS is not applied on my page. When I open CSS URL, I get a message:
Forbidden
You don't have permission to access /APP1/application/views/css/layout.css on this server.
Please, what am I doing wrong? I'd like to keep my CSS together with the view because in future I'd like to learn how to create multiple themes and I thing the CSS should be kept within the theme folder.
Can I replace URL path to CSS file with some Smarty variable so that when I move my application I do not need to change CSS URL path in templates manually?
Thank you in advance! Vojtech
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CodeIgniter 的
/application
文件夹中的任何内容都应被视为越界。为了获得最佳安全性,您实际上应该考虑将/application
保留在www
或public_html
文件夹之上,结构如下:这使得您的应用程序代码更安全。
我建议在公共文件夹中创建客户端脚本和 CSS。例如
public_html/css
和public_html/js
。或者,如果您想沿着主题路线前进,可以将每个 CSS 文件命名为主题名称,这样您就会有css/theme1.css
和css/theme2.css
。如果您的站点始终从域的根目录运行,那么您可以使用:
但是如果您觉得要移动各种内容,请考虑在将文件发送到之前在控制器中准备好文件位置聪明。
这将返回:
或者无论您的 CodeIgniter URL 是什么。
Anything in the
/application
folder of CodeIgniter should be considered out-of-bounds. For the best security, you should actually consider keeping/application
above yourwww
orpublic_html
folder in a structure such as this:This makes your application code safer.
I’d advise creating your client-side scripts and CSS in a public folder. For example
public_html/css
andpublic_html/js
. Or, if you wanted to go down the theme route, possibly name each CSS file as the name of the theme, so you’d havecss/theme1.css
andcss/theme2.css
.If your site will always work from the root of a domain, then you can just use:
But if you feel that you’re going to be moving all sorts of things around, then consider preparing the file location in your controller before sending it to Smarty.
That will return:
Or whatever your CodeIgniter URL is.
这将有助于将 css 链接到 codeigniter。
link_tag
用于链接资源,您可以使用helper
函数。例如 html 帮助器、url 帮助器、电子邮件帮助器等。
在您的控制器中,您必须创建一个类似的函数
,并且您的
view
文件夹中的index.php
使用 link_tag 关键字。This will help to link css to codeigniter.
The
link_tag
is used to link resources and you can usehelper
function.For example html helper, url helper, email helper, etc.
In your controller you have to create a function something like
And your
index.php
inview
folder use link_tag keyword.尝试将符号链接添加到服务器文档根文件夹。 (www/public_html/htdocs)
这样您就可以访问 css 文件夹并保留当前结构。
Try adding a symlink to your servers document root folder. (www/public_html/htdocs)
This way you can access your css folder and keep the current structure.