【问题标题】:How to open external URL in a new tab from cakephp?如何在 cakephp 的新选项卡中打开外部 URL?
【发布时间】:2018-01-31 16:14:08
【问题描述】:

我想打开另一个 url,让我们说:'localhost/test.html' 来自 cakePHP 中的页面。

我已经有一个视图(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')?>

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

错误:未找到请求的地址“/pages/localhost/test.html” 在这台服务器上。

我是全新的,自学 cakePHP。我用谷歌搜索了它,但没有一篇文章让我详细解释了如何做到这一点(可能是因为我对此很陌生)。

谁能帮我解决这个问题。很抱歉,如果不清楚,请向我澄清。

谢谢

【问题讨论】:

    标签: cakephp


    【解决方案1】:

    在 URL 前添加 http://

    <a href="http://localhost/test.html" target="_blank">
        Wireshark
    </a>
    
    <!-- or-->
    
    <?= $this->Html->link(
        __('Wireshark'),
        'http://localhost/test.html',
        [
            'target' => '_blank',
        ]
    ) ?>
    

    【讨论】:

    • 谢谢它的工作:)。我想我没有使用 http:// 。使用 http 后,它现在可以工作了。谢谢
    【解决方案2】:

    好吧,让我解释一下。

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

    希望对您有所帮助。

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

    【讨论】:

      猜你喜欢
      • 2019-10-06
      • 1970-01-01
      • 2014-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-03
      • 1970-01-01
      • 2017-08-04
      相关资源
      最近更新 更多