比方說,我希望有一個頁面,有一個漂亮的URL:CakePHP的路由:更改漂亮的URL站點範圍
配置/ routes.php文件
Router::connect('/profile', array('controller' => 'users', 'action' => 'profile'));
如果我想發送旅客到頁面,我可以用這樣的網址:
$this->redirect('/profile');
$this->Html->link('Your Profile', '/profile');
但是,假設我改變了主意,我現在想要的網址是:
/account
如何更改整個站點而不將每個/profile
的實例更改爲/account
?
或者...
另一種方式來問我的問題是我怎麼能正確的代碼中使用蛋糕數組語法的所有URL(這是我喜歡做的,而不是硬編碼的任何東西):
$this->redirect(array('controller' => 'users', 'action' => 'profile'));
$this->Html->link('Your Profile', array('controller' => 'users', 'action' => 'profile'));
然後確保該控制器/動作組合稱爲任何時候,它會將用戶的網址:
/profile
一nd將這條規則放在一個可以改變的地方。就像:
Router::connect(array('controller' => 'users', 'action' => 'profile'), '/profile');
// Later change to
Router::connect(array('controller' => 'users', 'action' => 'profile'), '/account');
有沒有辦法做到這一點,也允許進一步的請求參數傳遞到URL添加?
這個職位有幫助的感謝 –
@MukeshKumarBijarniya我很高興我能有所幫助:) – Jelmer