2015-01-26 34 views
0

我对CakePHP很新,但是我很努力地从一个表中的字段中抽取一个URL来创建一个外部链接。它目前正在使用我们的域名,然后将网址放在后面。CakePHP从表字段创建外部链接

有谁知道如何强制它,以便使用外部婚姻地址?

这里是我使用的代码:

<a href="<?php echo $this->Html->url(array($result_array['Result']['results_video'])); ?>"><?php echo $this->Html->image('certificate_image.png', array('escape' => false)); ?></a> 
+1

提供完全合格网址,它应该工作。换句话说,不要只是通过CakePHP foo.com,确保包含http:// – Kai 2015-01-26 20:54:20

回答

2

如果URL已经是一个字符串:

<a href="<?php echo $result_array['Result']['results_video']; ?>"> 
    <?php echo $this->Html->image('certificate_image.png'); ?> 
</a> 

如果它是一个数组你的代码是正确的,除了逃跑选项已去到第二个参数的link()方法中,而不是在image()方法中。

<a href="<?php $this->Html->url($result_array['Result']['results_video'], ['escape' => false]); ?>"> 
    <?php echo $this->Html->image('certificate_image.png'); ?> 
</a> 

如果您是CakePHP的新手,我建议您经常查看API文档以查看方法需要的参数。 http://api.cakephp.org/2.6/class-HtmlHelper.html。大多数情况下,有一个选项阵列可以做你想做的事。

0

的HtmlHelper :: URL和路由器::网址采取任何URL组件,前数组:

$this->Html->url(array('controller' => 'page', 'action' => 'index')); 
$this->Html->url($result_array['Result']['results_video']); 

或字符串,例如:

$this->Html->url('http://www.google.com'); 
$this->Html->url($variable['Model']['url']); 

可以通到的唯一的事url方法的第二个参数是null或者true,这会将完整的基本url预先设置为由数组组件生成的url,如果为true,那么这不会是您要传递该转义值的位置。

不知道你的$ result_array ['Result'] ['results_video']值究竟是什么,很难说你做错了什么,但我猜你实际上想要的是这个,因为从上下文它看起来像你已经有了一个数组:

<?php 
    echo $this->Html->link(
     $this->Html->image('certificate_image.png'), 
     $result_array['Result']['results_video'], 
     array('escape' => false) 
    ); 
?> 

(请注意,几乎永远不需要回波值到<a>标签时,你可以使用的HtmlHelper ::链接代替)