假设我有六个这样的页面:
data/home-page
data/apple-page
data/category1/apple-page
data/category1/kiwi-page
data/category1/category2/apple-page
data/category1/category2/pear-page
我想将它们中的每一个路由到我的PageController,但也要尊重页面所在的类别,因为标题可以加倍。
class PageController extends Controller
{
/**
* @Route("/wiki/{page}")
*/
public function showPage($page = 'home')
{
# Some kind of validation
# ...
# And then something like that should happen:
return $this->render('data/'.$page.'-page')
}
}
如果我打电话给localhost/wiki/apple
我显然得到了正确的页面,但我如何配置我的路线以获得category1/apple
的localhost/wiki/category1/apple
?
允许您的页面成为您想要的任何内容
class PageController extends Controller
{
/**
* @Route("/wiki/{page}", requirements={"page"=".*"})
*/
public function showPage($page = 'home')
{
# Some kind of validation
# ...
# And then something like that should happen:
return $this->render('data/'.$page.'-page')
}
}