Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP - Creating a link URL without the anchor tag

I am using CakePHP and want to create a URL to a controller/view without including the anchor tag.

In other words if I use

$this->Html->link('foo',array('controller'=>'bar','action'=>'display'));

Then the output is a formatted link that can be displayed... but I just want the URL without the HTML around it.

like image 446
Andy Avatar asked Jun 26 '12 08:06

Andy


3 Answers

echo $this->Html->url(array('controller' => 'bar', 'action' => 'display'));

With optional second parameter to make it a full URL including http:// and so on:

echo $this->Html->url(array('controller' => 'bar', 'action' => 'display'), true);
like image 154
deceze Avatar answered Nov 15 '22 16:11

deceze


I just needed the same thing, but it changed on Cake 3. Now we have to use:

echo $this->Url->build(["controller" => "bar", "action" => "display","bar"]);
like image 2
Senhorzim Avatar answered Nov 15 '22 14:11

Senhorzim


If you only need URL:

echo $this->Html->url(array('controller'=>'bar','action'=>'display'));
like image 1
Aurimas Ličkus Avatar answered Nov 15 '22 16:11

Aurimas Ličkus