Mab KaaKoo
Mab KaaKoo

Reputation: 125

URL always appended? CakePHP

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.

Upvotes: 0

Views: 176

Answers (3)

Nunser
Nunser

Reputation: 4522

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.

Upvotes: 1

Jose Vega
Jose Vega

Reputation: 10258

What happends when you replace your menu code with:

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

Upvotes: 0

chadpeppers
chadpeppers

Reputation: 2057

You are probably adding "cakephp-2.3.2/brand/43" instead of "/cakephp-2.3.2/brand/43"

Upvotes: 0

Related Questions