简体   繁体   English

img不会加载codeigniter

[英]img wont load codeigniter

I am writeing a site in php with codeigniter, the imgs i have in my imgs folder in the root directory of my site, i wrote the front page of my site and all the imgs load, the view loads, all css works fine. 我正在用codeigniter用php写一个站点,我在站点根目录的imgs文件夹中有img,我写了站点的首页,所有img都加载了,视图加载了,所有css都正常工作。 i made a copy the view and renamed to make the next view and when i load that view, none of the imgs load in it, it is the exact same code as the fist view and it loads fine, i dont under stand this, can u please help. 我制作了一个视图副本并重命名以创建下一个视图,当我加载该视图时,没有imgs加载到其中,这与拳头视图完全相同,并且加载得很好,我不明白这一点,可以你请帮忙。 i am running ubuntu 12.04, codeigniter 2.1.3 with mod_rewrite 我正在使用mod_rewrite运行ubuntu 12.04,codeigniter 2.1.3

Edit: 编辑:

i left broken code with out the part that worked for the other 6 imgs 我留下了残破的代码,没有为其他6张img工作的部分

this is the code that didnt work with: code from below that fixed everything but three items: 这是无法使用的代码:下面的代码修复了除以下三项以外的所有内容:

<img src="<?php echo base_url('path/to/image.jpg'); ?>">

this is the code it did not fix 这是它没有解决的代码

<?php 
    if(!$this->session->userdata('is_logged_in')){
        echo '<BR />';
        echo '<a href='.base_url()."main/login".'><img src="imgs/log_in_0.png" /></a>';
        echo '<BR />';
        echo '<BR />';
        echo '<a href='.base_url()."main/signup".'><img src="imgs/sign_up_0.png" /></a>';
        echo '<BR />';
    } 

?>

this css to load background: 这个CSS加载背景:

body 
{
    background-image:url('imgs/green_tex.jpg');
}

This is most likely a relative vs absolute path problem. 这很可能是相对路径与绝对路径的问题。

I am going to assume that you're calling images like this: 我将假设您正在调用这样的图像:

<img src="path/to/image.jpg">

What you should do, is call them like this: 您应该做的就是这样称呼他们:

<img src="<?php echo base_url('path/to/image.jpg'); ?>">

As a reminder, you need to have the url helper loaded for base_url() to work. 提醒一下,您需要加载url帮助器才能使base_url()正常工作。 I would suggest adding it to your autoload.php file. 我建议将其添加到您的autoload.php文件中。

In response to your recent edits: 针对您最近的修改:

echo '<a href='.base_url()."main/login".'><img src="' . base_url('imgs/log_in_0.png') . '" /></a>';

and for the CSS, you're going to have to put the path in manually, such as: 对于CSS,您将不得不手动放置路径,例如:

background: url(/imgs/log_in_0.png);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM