我目前正在尝试在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/role
或localhost/app_dev.php/cms/role/view
,它会为我提供正确的页面。我已尝试向/cms
添加默认路由,但它仍然给我同样的错误。这怎么可能,我该如何解决这个问题?
提前致谢。
答案 0 :(得分:2)
我不知道你写的和
之间有什么区别 public function indexAction($page = "role", $option = "view")
但也许你可以尝试并告诉我们。