bob_cobb
bob_cobb

Reputation: 2269

Link for static page in CakePHP without appending the controller

So I created a couple of static pages in views > pages folder. They are contact.ctp and privacy.ctp. In my routes.php, I made it so that they could be viewed by going to domain.com/contact and domain.com/privacy with:

    Router::connect('/contact', array('controller' => 'pages', 'action' => 'display', 'contact'));

    Router::connect('/privacy', array('controller' => 'pages', 'action' => 'display', 'privacy'));

Now, when I link them at the footer with:

    <li><?= $this->Html->link('Contact', array('controller' => 'pages', 'action' => 'display', 'contact')); ?></a></li>

    <li><?= $this->Html->link('Privacy', array('controller' => 'pages', 'action' => 'display', 'privacy')); ?></a></li>

They are linked as domain.com/pages/terms. How can I stop it from appending the pages controller without giving an absolute url (i.e. without doing: <?= $this->Html->link('Contact', 'http://www.domain.com/contact'); ?> or is that the only other way?

Upvotes: 3

Views: 5810

Answers (4)

user3432109
user3432109

Reputation: 1

For SE posterity, and the sake of succinctness, you can use Router::url( ).

<li><a href="<?php echo Router::url('/contact'); ?>">Contact</a></li>

Upvotes: 0

Rachid ES SAKHI
Rachid ES SAKHI

Reputation: 11

ROUTE

Router::connect('/*', array('controller' => 'pages', 'action' => 'display'));

VIEW

 echo $this->Html->link('Target', $this->Html->url(array('controller'=>'pages', 'action'=>'display', 'target', 'ext'=>'html')));

OUPUT

<a href="target.html">Target</a>

Upvotes: 1

Anh Pham
Anh Pham

Reputation: 5481

you probably put these routes after Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); Just reverse that order and it should work.

Upvotes: 4

Naftali
Naftali

Reputation: 146300

Use an actual link?

<a href ="/contact">Contact</a>

And:

<a href ="/privacy">Privacy</a>

Short and sweet ^_^

Upvotes: 0

Related Questions