CodeIgniter + CSS [英] CodeIgniter + CSS

查看:100
本文介绍了CodeIgniter + CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,我正在和Smarty一起学习CodeIgniter。我的CSS文件存储在

Good Day, I'm learning CodeIgniter with Smarty. My CSS file is stored in

/App01/application/views/css/main.css

要链接我的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" />

但CSS不适用于我的网页。当我打开CSS URL时,我收到一条消息:

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.

请问,我做错了什么?我想保持我的CSS与视图,因为在未来我想学习如何创建多个主题和我的东西CSS应该保存在主题文件夹。

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.

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

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?

提前谢谢! Vojtech

Thank you in advance! Vojtech

推荐答案

应该考虑CodeIgniter的 / application 文件夹中的任何内容超越界限。为了最好的安全,你应该考虑在 www public_html 上面保留 / application / code>文件夹中,如下所示:

Anything in the /application folder of CodeIgniter should be considered out-of-bounds. For the best security, you should actually consider keeping /application above your www or public_html folder in a structure such as this:

– application
    – controllers
    – models
    – views
    – ...
– system
    – core
    – libraries
    – ...
– public_html
    – index.php

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

This makes your application code safer.

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

I’d advise creating your client-side scripts and CSS in a public folder. For example public_html/css and public_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 have css/theme1.css and css/theme2.css.

如果您的网站总是从域的根目录工作, :

If your site will always work from the root of a domain, then you can just use:

<link rel="stylesheet" type="text/css" href="/css/layout.css" media="screen" />

但是如果你觉得你要做各种各样的事情,

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.

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

这将返回:

http://localhost/app1/css/theme.css

无论你的CodeIgniter URL是什么。

Or whatever your CodeIgniter URL is.

这篇关于CodeIgniter + CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆