我想用if..else語句在控制器中執行操作,它會分析路由並相應地執行操作。這可能嗎?Symfony 2,有條件定義路線嗎?
路線:blog\post\{tag} or blog\post.
標籤是一個數組,因此最有可能它看起來像標籤= 1,2,3,4,51
controller action diplaypost()
{
if (!isset($_GET['tag'])) {do smth; //case of route blog\post}
else {do smth; //case of route blog\post\{tag} }
}
這可能適用:http://symfony.com/doc/current/book/routing.html#completely-customized-route-matching-with-conditions但我認爲你真正需要的是給標籤一個默認值的空值。 – Cerad