Symfony Explorer-Like嵌套路由

问题描述 投票:0回答:1

假设我有六个这样的页面:

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/applelocalhost/wiki/category1/apple

symfony symfony4
1个回答
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')
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.