Reputation: 11
I want to open another url, lets say : 'localhost/test.html' from the page which is in cakePHP.
I already have a view(page.ctp) and controller(PagesController.php). On this page there is a button with name Wireshark, whenever I click on this button I want to go to another URL but not want to redirect to another page within the cakePHP server.
In the page.ctp I use this:
<?php echo $this->Html->link(__('Wireshark'), array('controller' => 'tests','action' => 'wireshark'))?>
In TestsController:
<?php
App::uses('AppController', 'Controller');
class TestsController extends AppController {
public function wireshark() {
}
}
In wireshark.ctp:
<?php
echo "hello"
?>
Till now when I click on button it redirects me to "http://localhost:9877/tests/wireshark" and display "hello". I think it works fine but what I need is to go to another web page(localhost/test.html).
I also tried with this in the same file:
<?php echo $this->Html->link(__('Wireshark'), 'localhost/test.html')?>
I get this when I use above code:
Error: The requested address '/pages/localhost/test.html' was not found on this server.
I am totally new and self studying cakePHP. I googled it but none of the post took me to the detailed explanation for how to do that(may be because I am so new to this).
Can anyone please help me with this. I am sorry if its not clear please ask me for clarification.
Thank You
Upvotes: 0
Views: 2262
Reputation: 2126
Well, let me explain.
Wireshark
represent to the label of href
Tests
is represent your controller andwiresha
is action
of your controllerHope this help for you.
echo $this->Html->link('Wireshark',array('controller'=>'Tests','action'=>'wireshark'), array('target'=>'_blank'));
Upvotes: 0
Reputation: 1782
prepend http:// to the url
<a href="http://localhost/test.html" target="_blank">
Wireshark
</a>
<!-- or-->
<?= $this->Html->link(
__('Wireshark'),
'http://localhost/test.html',
[
'target' => '_blank',
]
) ?>
Upvotes: 1