1

我目前正在尝试在 Symfony2 中配置路由选项,因此/cms将路由到/cms/role/view. 但是,默认值的传递似乎无法正常工作。

/src/MyProject/CMSBundle/Resources/config/routing.yml

MyProjectCMS_specific:
pattern:  /cms/{page}/{option}
defaults: { _controller: MyProjectCMSBundle:Main:index, page: role, option: view }
requirements:
    _method: GET

/src/MyProject/CMSBundle/Controller/MainController.php

<?php
    namespace MyProject\CMSBundle\Controller;

    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

    class MainController extends Controller
    {
        public function indexAction($page, $option)
        {
            $response = null;

            /* Switch statement that determines the page to be loaded. */

            return $response;
        }

    }
?>

问题是当我尝试去 `localhost/app_dev.php/cms' 时,它给了我以下错误:

Controller "MyProject\CMSBundle\Controller\MainController::indexAction()" requires that you provide a value for the "$page" argument (because there is no default value or because there is a non optional argument after this one).
500 Internal Server Error - RuntimeException

但是,如果我尝试访问localhost/app_dev.php/cms/roleor localhost/app_dev.php/cms/role/view,它会给我正确的页面。我试过添加一个默认路由到/cms,但它仍然给我同样的错误。这怎么可能,我该如何解决?

提前致谢。

4

1 回答 1

2

我不知道你写的和写的有什么区别

    public function indexAction($page = "role", $option = "view")

但也许你可以试试并告诉我们。

于 2012-02-26T14:18:45.993 回答