2014-01-22 48 views
0

我有這樣的路線設置,並手動輸入URL的工作原理:CakePHP的路線 - 生成appropiate鏈接,/:控制器/:ID /使用HTML幫助

Router::connect('/:controller/:id/*', 
    array('action' => 'view'), 
    array('pass'=>array('id'), 'id' => '[0-9]+')); 

然而,隨着HTML的「鏈接,我如果沒有采取行動,則無法生成鏈接。

$this->Html->link('linkName', array(
    'controller' => 'controllerName', 
    'action' => 'view', 
    $id, $slug)); 

產生controllerName /視圖/ ID

$this->Html->link('linkName', array(
    'controller' => 'controllerName', 
    $id, $slug)); 

產生controllerName /索引/ ID

我怎麼能生成HTML輔助鏈接控制器/ ID?

謝謝!

回答

0

CakePHP需要特異性。在這裏,我必須指定動作的ID,然後蛋糕匹配這些屬性的正確路線和產生正確的網址:

$this->Html->link('linkName', array(
    'controller' => 'controllerName', 
    'action' => 'view', 
    'id' => $id, 
    $slug 
));