CakePHP - 如何使用Helpers与target =“_ blank”建立图像链接

时间:2011-03-31 01:46:08

标签: php cakephp cakephp-1.3

这看起来应该很简单,但我是CakePHP的新手。也许这只是我应该用良好的HTML编写的东西,但是 - 希望通过CakePHP的HTML助手来了解如何做到这一点。

我只想要一个目标=“_空白”的图片链接。

这就是我的尝试:

<?php echo $this->Html->link($this->Html->image('tmp/728x90.jpg',
    array('alt'=>'advertisement', 'height'=>'90', 
    'width'=>'728')),'http://www.google.com', array('target'=>'_blank')); ?>

(全部在一行 - 为了便于观看而分手了)

但是当我这样做时,我明白了:

<a href="http://www.google.com" target="_blank">&lt;img src=&quot;/img/tmp/728x90.jpg&quot; alt=&quot;advertisement&quot; height=&quot;90&quot; width=&quot;728&quot; /&gt;</a>

非常感谢任何帮助。


回答(谢谢deceze)

<?php 

$image = $this->Html->image(
    'tmp/300x600.jpg', 
    array(
        'alt'=>'advertisement', 
        'height'=>'600', 
        'width'=>'300'
    )
);

echo $this->Html->link(
    $image,
    'http://www.google.com', 
    array(
        'target'=>'_blank', 
        'escape' => false
    )
); ?>

6 个答案:

答案 0 :(得分:12)

<?php echo $this->Html->link($this->Html->image('fb2.jpg',array('alt'=>'facebook', 'height'=>'90','width'=>'728')),'http://www.facebook.com', array('target'=>'_blank','escape'=>false)); ?>

答案 1 :(得分:3)

您需要告诉HtmlHelper::link不要HTML转义输入 这一切都非常好documented in the manual

答案 2 :(得分:0)

您需要使用Html-&gt;图片。看看:

http://book.cakephp.org/view/1441/image

答案 3 :(得分:0)

如Cook Book中所述,您可以使用图像方法的'url'选项:

echo $this->Html->image("recipes/6.jpg", array(
   'alt' => "Brownies",
   'url' => array('controller' => 'recipes', 'action' => 'view', 6)
));

答案 4 :(得分:0)

确切的代码将是这样的

  <?php 
         echo $this->Html->link(
                    $this->Html->image('tmp/728x90.jpg',
                                         array(
                                        'alt'=>'advertisement', 'height'=>'90',
                                        'width'=>'728')
                                       ),
                                    'http://www.google.com',
                                    array(
                                       'target'=>'_blank',
                                       'escape'=>false)
                                ); 
?>

答案 5 :(得分:-1)

echo $ html-&gt; link(“more”,array('controller'=&gt;'users','action'=&gt;'index / welcome'),array('style'=&gt;'_ blank '),false,false);?&gt; image('more-arrow.png',array('alt'=&gt;'more','height'=&gt; '11','width'=&gt; '17'))?&gt;