【问题标题】:url to display image and connecting css in codeigniter [duplicate]在codeigniter中显示图像和连接css的url [重复]
【发布时间】:2013-02-14 18:54:35
【问题描述】:

我是 Web 开发的新手(尤其是 CI 框架中的 php)。这个问题对你来说应该是一个非常简单的问题,但是我已经谷歌搜索了一个小时,仍然找不到任何解决方案。

我想显示一个图像(img 文件夹中的 logo.png)并链接一个我放入 的 css 文件(style 文件夹中的 style.css) >根目录:

但是当我尝试显示图像并链接 css 时,我得到的只是一个 blank网页。 这是我的 html 代码:

<!DOCTYPE html>
<html>
    <head>
        <title>My First Design</title>
        <link href="<?php echo base_url();?>style/style.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
        <h1><img src="../../img/logo.jpg" />My First Web Design</h1>
        <p>
        I have been working on honing, and in some cases, learning new graphical skills in the past few weeks. So, I have been                          extensively watching Adobe Illustrated tutorials and working on my existing Photoshop knowledge and basically trying to                     get a hang of the software beyond basic image editing and digital painting.
        </p>
        <p>
        From a beginner’s point of view, the world of graphical design is quite vast… at times intimidating and there is no limit                           to creative options. One could branch out into any form of graphical design… illustrations or web-design or logo &                                  advertising and so much more. At the same time, one does not need to limit the options to just these.
        </p>
    </body>
</html>

这是我的config.php base_url:$config['base_url'] = 'http://localhost/ciGlassProject/';

我尝试了一些不同的方法,例如:

  1. 使用 site_url 代替 base_url
  2. 手动输入网址
  3. 以多种方式更改$config['base_url'] 值。 但是,它们都不起作用。

【问题讨论】:

  • http://localhost/ciGlassProject/img/logo.jpg 可以工作吗?
  • @pktangyue 是的,对不起,我想我只是想念输入网址:D
  • 答案是:base(); url 不起作用,因为我忘了导入帮助程序 ($this->load->helper('url')) :D

标签: php html codeigniter


【解决方案1】:

您可以使用它应该工作的基本 URL。

<img src="http://localhost/ciGlassProject/img/logo.jpg" />

更好的方法是使用 php 获取基本 url。这意味着如果您移动您的网站,您将不必多次更改 URL 以使其在新位置运行。为此,您可以使用简单的 php 调用:

<img src="<?php echo base_url(); ?>img/logo.jpg" />

【讨论】:

  • 谢谢 :D 手动 url 现在可以使用(我想我错过了输入 '://' 部分)但是 base_url();方法不起作用。 css 也无法正常工作,因为我使用了 base_url()。奇怪的是,当我查看我的旧项目时,与 base_url() 方法相关的一切都很好。
  • 对不起,我忘记在我的控制器中导入助手。感谢您的帮助:D
猜你喜欢
  • 2017-04-27
  • 2016-05-24
  • 2016-11-05
  • 2015-10-30
  • 2011-09-09
  • 2015-02-28
  • 1970-01-01
  • 2017-06-11
  • 2018-05-30
相关资源
最近更新 更多