Symfony Explorer-Like 嵌套路由
Symfony Explorer-Like Nested Routing
假设我有六个这样的页面:
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
,我显然得到了正确的页面,但是我必须如何配置我的路由才能获得 localhost/wiki/category1/apple
的 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')
}
}
假设我有六个这样的页面:
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
,我显然得到了正确的页面,但是我必须如何配置我的路由才能获得 localhost/wiki/category1/apple
的 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')
}
}