图片没有加载默认布局cakephp中的某些页面?

时间:2013-12-31 06:52:59

标签: php image cakephp layout

我在我的cakephp网站的默认布局中添加了一个图像作为按钮。 但是某些视图没有加载图像。

<input type="image" class="search_button" src="img/search.png" style="background-color: #066; margin-left: 5px; margin-top: -5px; vertical-align:  middle" />

图片位于webroot,img文件夹

1 个答案:

答案 0 :(得分:0)

使用助手或绝对网址

您遇到的问题是用于访问图像的网址是相对于当前网址的

表示当前页面是否为:

http://example.com

请求图像
http://example.com/img/search.png

我们假设上面的图像存在。如果当前页面是:

http://example.com/some/text

请求图像
http://example.com/some/text/img/search.png

存在。

适当的行动是使用绝对网址

<input type="image" class="search_button" src="/img/search.png"
                                               ^

或使用适当的帮助方法生成标记。但是在这种情况下 - 最好使用css:

// file in webroot/css/foo.css
.search_button {
    background-image:url('../img/search.png');
}