占位符默认值Symfony

时间:2017-09-15 09:15:27

标签: php symfony routing yaml

嗨编程朋友,

所以我是一个新手Symfony用户遇到此问题,我在尝试访问我的主页时遇到404错误。

这是我的 ../../../ Resources / config / routing.yml

pl_if_soc_home:
    path:      /{page}
    defaults:
        _controller: PLIfsocBundle:Intervenant:index
        page:        1
    requirements:
        page: \d*

我的 app / config / routing.yml

pl_ifsoc:
    resource: "@PLIfsocBundle/Resources/config/routing.yml"
    prefix:   /ifsoc

我的控制器

public function indexAction($page)
{
    if($page < 1)
    {
        throw new NotFoundHttpException('Page "'.$page.'"inexistante.');
    }

    $nbPerPage = 5;

    $listInters = $this->getDoctrine()
            ->getManager()
            ->getRepository('PLIfsocBundle:Intervenant')
            ->myFindAll($page, $nbPerPage);

    $nbPages = ceil(count($listInters)/$nbPerPage);

    if($page > $nbPages)
    {
        throw $this->createNotFoundException("La page ".$page." n'existe pas.");
    }

    return $this->render('PLIfsocBundle:Intervenant:index.html.twig', array('listInters' => $listInters, 'nbPages' => $nbPages, 'page' => $page));
}

现在每当我试图访问http://localhost:8000/ifsoc/

我收到页面不存在的错误,好像没有考虑默认页面1。我笨吗?我在这里缺少什么?

0 个答案:

没有答案
相关问题