2011-05-22 29 views
1

我試圖在app/config/routes.php中修改我的路線。如何在路線中更改我的CakePHP網址?

我的網址是這樣的: http://example.com/controller/action/params 我想是這樣的網址: http://example.com/controller/params

這裏是我的路線我建立我的理解是:

Router::connect('/services/:slug', 
array('controller' => 'services', 'action' => 'view'), 
array('pass' => array('slug'))); 

,這裏是我的鏈接在我的index.ctp文件服務:

echo $this->Html->link(
    __($service['Service']['title'], true), 
    array('controller' => 'services', 'action' => 'view', service['Service']'slug']) 
); 

如果有幫助,這裏是我從服務控制器查看功能:

function view($slug) { 
     $service = $this->Service->findBySlug($slug); 

     $this->set('service', $service); 
    } 

回答

0

你幾乎在那裏。 查看文件的行動路線是view.ctp(方法名),而不是index.ctp

在你的鏈接,你可以這樣做:

<?php 
echo $this->Html->link(
__($service['Service']['title'], true), 
array('controller' => 'services', 'action' => $service['Service']['slug']) 
?> 

沒有一種方法在「動作」 PARAM因爲您的設置將爲您完成路由。