0

I'm new for CakePHP;
The URL address bar is always appended after I clicked on every menu;

I have defined my routes as below:

Router::connect('/brand/*', array('controller' => 'phones', 'action' => 'phonebybrand'));

This is my menu:

<?php            
        foreach ($phonebrands as $phonebrand):
            echo '<li><a href="brand/{$phonebrand['Phonebrand']['id']}">{$phonebrand['Phonebrand']['brandname']}</a></li>';
        endforeach;
?>

I tried to click my menu for several times; what I found out is the URL always appended;
1st time: localhost/cakephp-2.3.2/brand/43
2nd time: localhost/cakephp-2.3.2/brand/brand/43
3rd time: localhost/cakephp-2.3.2/brand/brand/brand/43

Please help me, why it's always appended the url?

Thank.

Nunser
  • 4,512
  • 8
  • 25
  • 37
Mab KaaKoo
  • 125
  • 1
  • 6
  • 19

3 Answers3

1

Your probably not getting the base url correctly.

Try this in your view

<?php            
    foreach ($phonebrands as $phonebrand) {
        echo '<li><a href="'.$this->Html->url('/', true).'brand/{$phonebrand['Phonebrand']['id']}">    {$phonebrand['Phonebrand']['brandname']}</a></li>';
    }
?>

Otherwise replace $this->Html->url()with Router::url('/', true);.
This post might help.

Community
  • 1
  • 1
Nunser
  • 4,512
  • 8
  • 25
  • 37
  • Finally, I found the problem; because I didn't point it back to the controller I also changed it to like $this->html->url(); **Check my code below; it's working now:** `echo '
  • '.$this->Html->link($phonebrand['Phonebrand']['brandname'],array('controller'=>'phones','action'=>'phonebybrand',$phonebrand['Phonebrand']['id'])).'
  • ';` Thank You ! – Mab KaaKoo May 03 '13 at 16:00
  • It does look much better, but that link doesn't show the `localhost/cakephp-2.3.2/phones/phonebybrand/$id` link instead of the `localhost/cakephp-2.3.2/brands/$id` you were trying to make? I've update the answer with the two options to see what you'll get. Glad I could help :) – Nunser May 03 '13 at 16:20
  • Yes, I got it. Thank for you helping. ^^ – Mab KaaKoo May 04 '13 at 06:02