CodeIgniter上资产文件夹的路径 [英] Path to assets folder on CodeIgniter

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

问题描述

我正在将某些代码编码到CodeIgniter中,并且我想应用一个CSS模板.我找到了我喜欢的一个并下载.

I'm coding something into CodeIgniter and I want to apply a css template. I found one I like and download it.

将css代码与合并之前的代码合并后,我发现css模板使用的图像未加载.最初它们应该保留在html文件夹的根目录下(或者www或public_html,您知道我的意思...),但是我将它们放在与系统文件夹相同级别的资产文件夹下.

After merging the css code with the code I have before the merging, I found that the images used by the css template doesn't load. Originally they should stay on root of html folder (or www, or public_html, you know what I mean...), but I put them under an assets folder which is on same level as system folder.

类似这样的事情...

Something like this...

Website Folder
|
|---application\
|-----(CodeIgniter application folders...)
|---assets\
|-----style.css
|-----css\
|-------mini.css
|-----images\
|-----js\
|-----robots.txt
|---system
|-----(CodeIgniter system folder...)
|index.php

我用Google搜寻了几个小时,发现此帖子(帖子#5).我尝试了OP所说的内容,但没有用.

I googled for a couple of hours and I found this post (post #5). I try what the OP says but it doesn't work.

我可以自动加载添加的url_helper

I can autoload the url_helper adding

$autoload['helper'] = array('url');

到autoload.php文件.但是当我添加

to the autoload.php file. But when I add

<base href="<?php echo base_url() ?>"/>

图像仍然不存在.

原始html文件具有这一行

The original html file has this line

<link href="style.css" type="text/css" rel="stylesheet" /> 

所以,我猜我应该添加资产/这样看起来

so, I'm guessing that I should add assets/ so it looks

<link href="assets/style.css" type="text/css" rel="stylesheet" />

但仍然缺少图像.

如果我将资产文件夹的内容移到根目录,一切都很好,但是,当然,这不是AFAIK的好习惯...

If I move the contents of assets folder to root, everything is fine, but of course, that's not a good practice AFAIK...

我的base_url是

My base_url is

http://localhost/prog/nonsense/mvc/

在您问之前,是的,我确实阅读过.htacces解决方案,但是我现在真的不想弄乱.htaccess编辑.

Before you ask, yes, I did read the .htacces solutions, but I really don't want to mess with .htaccess editing for now.

这里提供了一些帮助.

推荐答案

我和你有同一件事,我这样称呼他们:

I have the same thing as you, and I call them like this:

<link href="<?=base_url('assets/style.css');?>" rel="stylesheet">

如果设置了 base_url()并调用了 url 帮助器,则此方法对我有用.

This works for me if the base_url() is set and the url helper is called.

我先调用 base_url(),然后再调用 assets 文件夹,然后再调用 style.css .在 base_url();?> 之后不需要/,因为在 base_url()中总有一个.

I call the base_url() and then the assets folder then style.css. There's no need for a / after base_url();?> because there's one in the base_url() anyway.

使用codeigniter内置HTML函数的另一个选项:

此外,如果您查看此链接,您会看到可以使用 HTML 帮助器,并通过codeigniter的内置函数进行调用.

Also, if you look at this link, you'll see you can use the HTML helper and call it via codeigniter's built in functions.

这一次,您不需要 base_url();

要做:

$autoload['helper'] = array('url', 'html');

然后在标题视图中添加以下内容:

then in the view for header add this:

<?=link_tag('assets/style.css');?>

它将输出到此:

<link href="http://localhost/prog/nonsense/mvc/assets/style.css" rel="stylesheet" type="text/css" />

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

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