假设我有六个这样的页面:
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
?
答案 0 :(得分:0)
让您的网页成为您想要的任何内容
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')
}
}