2015-01-26 37 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 ::鏈接代替)