如何通过 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)获取网站的完整网址

但是我也找不到任何可以为图像设置为 true 的参数。关于如何做到这一点的任何建议或解决方法?

编辑 1:基本上,我需要这个链接:Layouts/default/Logo.png成为 img src 中的http://www.something.com/Layouts/default/Logo.png

我总是使用

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

我认为这就是你要找的。

<?
echo $this->Html->image(Router::url('/') . 'Layouts/default/Logo.png');
?>

你正在寻找的可能是在实现image方法时使用的 HtmlHelper::assetUrl 函数:

public function image($path, $options = array()) {
    $path = $this->assetUrl($path, $options + array('pathPrefix' => Configure::read('App.imageBaseUrl')));
    ...
$img = '<img src="http://some-img-link" alt="some-img-alt"/>';
$src = preg_match('/<img src="(.*?)">/', $img);
echo $src;

我想从 img 标签中获取src值,也许还有 alt 值

最新更新