【发布时间】:2018-05-21 13:47:21
【问题描述】:
按照Dynamic Router 文档,我可以:
- 创建链接到我的内容的路由(页面实体)
- 用 ORM 坚持下去
- 加载我的控制器匹配路由
但是由于我的控制器应该期望 $contentDocument 参数,我什么都没有。
以下是我创建路线和实体的方式:
$page = new Page();
$page->setTitle('My Content')
->setBackground(1)
->setDescription('My description')
->setContent('<h1>Hello</h1>');
$manager->persist($page);
$manager->flush(); // flush to be able to use the generated id
$contentRepository = $this->container->get('cmf_routing.content_repository');
$route = new Route();
$route->setName('my-content');
$route->setStaticPrefix('/my-content');
$route->setDefault(RouteObjectInterface::CONTENT_ID, $contentRepository->getContentId($page));
$route->setContent($page);
$page->addRoute($route); // Create the backlink from content to route
$manager->persist($page);
$manager->flush();
这是我的配置部分:
cmf_routing:
chain:
routers_by_id:
router.default: 200
cmf_routing.dynamic_router: 100
dynamic:
enabled: true
persistence:
orm:
enabled: true
generic_controller: AppBundle:Default:showPage
templates_by_class:
AppBundle\Entity\Page: AppBundle:Default:index.html.twig
我的控制器:
public function showPageAction($page)
{
return $this->render('default/index.html.twig');
}
还有错误:
Controller "AppBundle\Controller\DefaultController::showPageAction()" 要求您为 "$page" 参数提供一个值。参数可以为空且未提供空值、未提供默认值或因为在此参数之后有一个非可选参数。
【问题讨论】:
标签: symfony routing symfony-3.4 symfony-cmf