假设我在 Assets 文件夹中存储了一个“image.jpg”,路径是“www.example.com/public”,我只想要图像的字符串路径。我怎么得到这个?我不希望 html 标签只包含路径字符串。
最佳答案
在尝试了各种 CakePHP 全局常量(ROOT、WEBROOT_DIR、WWW_ROOT、CSS 等)但没有结果后,通用的解决方案似乎在 $this->webroot 属性中找到,该属性返回应用程序 webroot 的路径。因此,对于上述各种情况,我们的布局、 View 或元素中可能有:
一个简单的图像标签:
<img src="<?php echo $this->webroot; ?>img/foo.gif" .../ >
表格单元格中的背景图像以旧方式:
<td background="<?php echo $this->webroot; ?>img/foo.gif">
type="image"的输入:
<input type="image" src="<?php echo $this->webroot; ?>img/go_btn.gif" ... />
I think webroot always work
关于image - 如何在 Cakephp 中获取图像的完整 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15989257/