Symfony CMF动态路由器无内容文档
根据文件,我可以:Symfony CMF动态路由器无内容文档,symfony,routing,symfony-3.4,symfony-cmf,Symfony,Routing,Symfony 3.4,Symfony Cmf,根据文件,我可以: 创建链接到我的内容(页面实体)的路由 坚持使用ORM 加载与路径匹配的控制器 但正如我的控制器所期望的$contentDocument参数一样,我什么都没有 以下是我创建路线和实体的方法: $page = new Page(); $page->setTitle('My Content') ->setBackground(1) ->setDescription('My description') ->setCo
- 创建链接到我的内容(页面实体)的路由
- 坚持使用ORM
- 加载与路径匹配的控制器
$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();
我的控制器:
public function showPageAction($page)
{
return $this->render('default/index.html.twig');
}
错误是:
控制器“AppBundle\Controller\DefaultController::showPageAction()”要求您为“$page”参数提供一个值。该参数可为null且未提供null值,未提供默认值,或者因为此参数后面有一个非可选参数
动态路由将内容文档放入名为“contentDocument”的请求中。您需要明确使用该名称:
public function showPageAction($contentDocument)
{
return $this->render('default/index.html.twig');
}
如果不需要在控制器中执行任何操作,则不需要指定通用的\u控制器。template_by_类将使捆绑包提供的控制器使用$contentDocument中的页面实例呈现该模板
public function showPageAction($contentDocument)
{
return $this->render('default/index.html.twig');
}