我讀過有關的永久鏈接(隱藏主鍵並用顯著字符串替換它們)段,但我不明白它是如何工作的代碼:的symfony:固定鏈接(URL中隱藏ID)
public function executePermalink($request)
{
$article = ArticlePeer::retrieveBySlug($request->getParameter('slug');
$this->forward404Unless($article); // Display 404 if no article matches slug
$this->article = $article; // Pass the object to the template
}
這個代碼是推動的典型代表,是不是?教義上有這樣的東西嗎?我必須編寫retrieveBySlug()函數?你有一個例子,我可以理解如何寫它?
非常感謝
完善,得益於有一個錯誤。我會試試看。 – satboy78 2012-04-26 20:01:28
@ilanco由於'$ this-> getRoute() - > getObject()'已經執行了檢查,所以你可以使用'forward404Unless'去除支票。 – j0k 2012-04-26 20:08:47
嗨,我試了一下......它給了我一些問題,但我已經解決了它(在答案中,我解釋了我是如何做到的......) – satboy78 2012-05-03 08:27:24