2017-08-23 95 views
0

我想打开另一个url,让我们说:'cakephp'中的'localhost/test.html'。如何在cakephp的新选项卡中打开外部URL?

我已经有一个视图(page.ctp)和控制器(PagesController.php)。在这个页面上有一个名为Wireshark的按钮,每当我点击这个按钮,我想去另一个URL但不想重定向到cakePHP服务器中的另一个页面。

在page.ctp我用这个:

<?php echo $this->Html->link(__('Wireshark'), array('controller' => 'tests','action' => 'wireshark'))?> 

在TestsController:

<?php 
App::uses('AppController', 'Controller'); 


class TestsController extends AppController { 

    public function wireshark() { 

     } 
    } 

在wireshark.ctp:

<?php 
echo "hello" 
?> 

直到现在,当我点击按钮,它将我重定向到“http://localhost:9877/tests/wireshark”并显示“hello”。我认为它工作正常,但我需要的是去另一个网页(localhost/test.html)。

我也试图与这个在同一个文件:

<?php echo $this->Html->link(__('Wireshark'), 'localhost/test.html')?> 

我得到这个,当我使用上面的代码:

Error: The requested address '/pages/localhost/test.html' was not found on this server.

我完全新的和自我学习CakePHP的。我搜索了一下,但没有任何一篇文章向我详细解释如何做到这一点(可能是因为我对此很陌生)。

任何人都可以帮助我这个。如果不清楚请向我澄清,我很抱歉。

谢谢

回答

1

前置HTTP://的URL

<a href="http://localhost/test.html" target="_blank"> 
    Wireshark 
</a> 

<!-- or--> 

<?= $this->Html->link(
    __('Wireshark'), 
    'http://localhost/test.html', 
    [ 
     'target' => '_blank', 
    ] 
) ?> 
+0

谢谢它工作:)。我想我没有使用http://。使用http后,它现在正在工作。谢谢 – Sheenam

0

好吧,让我来解释一下。

  1. Wireshark的第一个关键字代表到href
  2. 第二个关键字调用Tests是代表你的控制器和
  3. 第三关键字调用wiresha是控制器的action标签

希望这对你有帮助。

echo $this->Html->link('Wireshark',array('controller'=>'Tests','action'=>'wireshark'), array('target'=>'_blank'));