Symfony CMF 动态路由器没有 contentDocument
Symfony CMF Dynamic Router no contentDocument
根据 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()" requires that you provide a value for the "$page" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.
动态路由将内容文档放入名称为 "contentDocument" 的请求中。您需要明确使用该名称:
public function showPageAction($contentDocument)
{
return $this->render('default/index.html.twig');
}
如果您不需要在控制器中执行任何操作,则无需指定 generic_controller。 template_by_class 将使提供的包控制器使用 $contentDocument 中找到的页面实例呈现该模板。
根据 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()" requires that you provide a value for the "$page" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.
动态路由将内容文档放入名称为 "contentDocument" 的请求中。您需要明确使用该名称:
public function showPageAction($contentDocument)
{
return $this->render('default/index.html.twig');
}
如果您不需要在控制器中执行任何操作,则无需指定 generic_controller。 template_by_class 将使提供的包控制器使用 $contentDocument 中找到的页面实例呈现该模板。