我想知道如何用zend框架來做漂亮的網址?如何在zend框架中做漂亮的url?
一些背景:
我的網址現在的問題是:www.website.com/profile/43
數據庫結構是:
id userid name
1 43 John
.. ... ...
和我的路由器是:
$router->addRoute('getUserid',
new Zend_Controller_Router_Route(
'/profile/:id',
array(
'module' => 'profile',
'controller' => 'social',
'action' => 'index'
)
)
);
很顯然,我想該網址爲:www.website.com/profile/John
從研究我鬃毛它看起來像我可以做很多事情與路由器,添加正則表達式等,但沒有關於如何取代id
就像我的情況。
我需要做一個查詢,找出名字,我想這樣做的predispatch和使用結果作爲默認變量,但我不知道id
因爲$front->getRequest()->getParams()
不可用:
$name = // do query to find out the name;
$router->addRoute('getUserid',
new Zend_Controller_Router_Route(
'/profile/:id',
array(
'id' => $name,
'module' => 'profile',
'controller' => 'social',
'action' => 'index'
)
)
);
也許即將在這個從錯誤的觀點。有任何想法嗎?
謝謝。
你目前的實施有什麼問題?你爲什麼想改變它? – zerkms 2012-04-02 23:08:46
我需要的ID是'約翰'而不是'43' – Patrioticcow 2012-04-02 23:14:51
在你的控制器中做到這一點。這不是路由器的工作。 – zerkms 2012-04-02 23:16:03