代码之家  ›  专栏  ›  技术社区  ›  andygeers

CakePHP绝对图像URL

  •  6
  • andygeers  · 技术社区  · 17 年前

    $html->image(...) CakePHP中的helper函数来输出图像,但我需要它来生成 img 使用绝对URL而不是相对URL进行标记(生成的HTML将在公司新闻稿中下载并通过电子邮件发送)。这可能吗?

    它没有文档记录,但我从查看源代码中注意到 image 函数可以将数组作为其第一个参数。不过,我并不完全清楚如何让它工作——这种天真的尝试会产生相对于当前页面的图像URL,而不是在页面中 webroot/img 文件夹

    6 回复  |  直到 17 年前
        1
  •  29
  •   JD Isaacks    13 年前

    在CakePHP 1.x中,方法是:

    $this->Html->image($this->Html->url('/path_to_image/image.png',true));
    

    在CakePHP 2.x中,方法是:

    $this->Html->image('/path_to_image/image.png', array('fullBase' => true));
    
        2
  •  9
  •   WebbedIT    13 年前

    正确的方法是在CakePHP 2.x中:

    <?php
    echo $this->Html->image("logo.png", array('fullBase' => true));
    

    直接从食谱中提取的代码: http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html

        3
  •  1
  •   kamal pal    10 年前

    $html->image('http://example.com/path_to_image/image.png');

        4
  •  0
  •   Paul Gleeson Rion Williams    14 年前

    您应该能够使用:

    $html->image('http://[domain]/[path]/[image]')
    
        5
  •  0
  •   GIPSSTAR    12 年前

    使用链接图像:-

    <?php echo $this->Html->link($this->Html->image('logo.png',array('alt'=>'Logo')),'/', array('fullBase'=>true)); ?>
    

    仅显示图像:-

    <?php echo $this->Html->image('logo.png',array('alt'=>'Logo')),'/', array('fullBase'=>true); ?>
    
        6
  •  -4
  •   Aziz    17 年前

    <img src=”http://example.com/path_to_image/image.png“alt=”“/>

    有时候,最好保持最简单的方式

    推荐文章