默认布局cakephp中某些页面的图像没有加载? [英] Image no loading for some pages in default layout cakephp?
本文介绍了默认布局cakephp中某些页面的图像没有加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的cakephp网站的默认布局中添加了一个图像作为按钮。
但是某些视图没有加载图片。
I added a image as a button in my default layout of my cakephp site. but that images is not loading for some views.
<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文件夹
image is in the webroot, img folder
推荐答案
使用帮助器或绝对URL
您遇到的问题是用于访问映像的URL是相对于当前的url
Use helpers or absolute urls
The problem you have is that the url used to access the image is relative to the current url
如果当前页面是:
http://example.com
图片是从
http://example.com/img/search.png
我们假设上面的图像存在。如果当前页面是:
Let's assume the above image exists. If the current page is:
http://example.com/some/text
请求图像
http://example.com/some/text/img/search.png
哪个不存在。
适当的行动是使用绝对网址
Appropriate action is to either use an absolute url
<input type="image" class="search_button" src="/img/search.png"
^
或使用适当的帮助方法生成标记。但是在这种情况下 - 最好在webroot / css / foo.css $ b中使用css:
Or use an appropriate helper method to generate the markup. In this case however - it would be better to use css:
// file in webroot/css/foo.css
.search_button {
background-image:url('../img/search.png');
}
这篇关于默认布局cakephp中某些页面的图像没有加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文