Create absolute link to an external web page

Hi there,

how can I create absolute links from my CakePHP 4 project to a external web page?
For my internal links, like Nav Bar and so on, I’ve used:

<?= $this->Html->link(
    'displayedNameOfTheLink',
    ['controller' => 'pages',  'action' => 'myPage', '_full' => true]
) ?>

That’s the way from the Cook Book and it’s working well.
I didn’t found descriptions to set an external link…

Regards,
Hubes

The ['controller' => 'pages', 'action' => 'myPage', '_full' => true] parameter is the link - it’s just getting resolved for you. So you can do -

<?= $this->Html->link(
    'CakePHP', 
    'https://cakephp.org'
) ?>

Hi Jawfin,

thank’s for your answer! It works now.
I’ve extended your code snippet to this:

<?= $this->Html->link(
    'CakePHP', 
    'https://cakephp.org'
    ['target' => '_blank', '_full' => true]
) ?>

Now it is exactly what I need.

Have a nice day :sunny:

Regards,
Hubes

2 Likes