2012-04-07 81 views
2

我有一个电子邮件布局此代码段:如何通过Html帮助程序(图像方法)获取img标记中图像的完整链接?

<div> 
    <?php echo $this->Html->image('Layouts/default/Logo.png', array(
     'alt' => 'Setin SRL', 
     'url' => $this->Html->url(array('action' => 'index'), true) 
    )); ?> 
    </div> 

然而,这也不行。我可以通过url(array('action' => 'index'), true)

获取完整URL到网站,但我找不到,我可以设置为true图像太任何paramater。任何建议或解决方法,我该如何做到这一点?

编辑1: 基本上,我需要这个链接:Layouts/default/Logo.pngIMG SRC

回答

1

成为http://www.something.com/Layouts/default/Logo.png我总是用

$this->Html->link($this->Html->image(...), $this->Html->url(array('action' => 'index'), true), array('escape'=>false)); 
+0

等等,我的问题是对图像的引用,而不是链接!请参阅我的编辑 – 2012-04-07 19:29:44

+1

这就是我的观点。你只是不要使用这种方式与URL结合使用图像(我从来不喜欢它,你可以添加一个URL这种方式在第一位)。 PS:你可以在image()标签中做同样的事情:'$ this-> Html-> image($ this-> Html-> url(...,true))' – mark 2012-04-07 19:38:09

+0

是的,但如果我使用* url *方法我错过了自动链接到img目录(http://mywebsite.something/img/Layouts/default/Logo.png)的可能性,我不得不手动添加它。我知道是愚蠢的,但我没有使用漂亮的网址功能(主机问题),所以我得到一个http://mywebsite.something/index.php/img/...这不是很好obviusly – 2012-04-07 19:43:07

1

我认为这是你在找什么。

​​
+0

虽然我认为你的回答在逻辑上是正确的,但我认为蛋糕有一种错误,事实上它会输出:/app/webroot/index.php/Layouts/default/Logo.png “索引”。 php“obviusly正在创建该问题(请记住,我的重写mod禁用主机问题) – 2012-04-09 21:46:02

+0

哦,有趣的,你可以尝试Router :: url('/',true)?那样有用吗? – Suman 2012-04-09 21:53:29

+0

“真”我得到了不同的结果,但仍然不好:'http://www.xxx.com.localhost:8080/index.php/Layouts/default/Logo.png“' – 2012-04-09 22:51:50

0
$img = '<img src="http://some-img-link" alt="some-img-alt"/>'; 

$src = preg_match('/<img src=\"(.*?)\">/', $img); 

echo $src; 

我想从img标签的src价值,也许是ALT值

1

可能是你正在寻找在image方法的实现中使用的HtmlHelper::assetUrl功能:

public function image($path, $options = array()) { 
    $path = $this->assetUrl($path, $options + array('pathPrefix' => Configure::read('App.imageBaseUrl'))); 
    ... 
+0

我相信这是不可用的,当我在这个问题上工作 – 2015-04-23 12:01:40

相关问题