public function pages($slug, PagesGenerator $pagesGenerator)
{
$output = $pagesGenerator->getPages($slug);
$id = $page->getId();
return $this->render('list.html.twig', [ 'output' => $output, 'id' => $id]);
}
但是我得到了错误:
注意:未定义的变量:页面
答案 0 :(得分:2)
public function pages($slug, PagesGenerator $pagesGenerator)
{
$output = $pagesGenerator->getPages($slug);
// here is your error: $page is not defined.
$id = $page->getId();
// something like this?
$id = $output['page']->getId();
return $this->render('list.html.twig', [ 'output' => $output, 'id' => $id]);
}
答案 1 :(得分:1)
您的新控制器显然没有将template
变量放入变量列表,而只是output
。看起来您的正确代码应该是:
public function pages($slug, PagesGenerator $pagesGenerator)
{
$output = $pagesGenerator->getPages($slug);
return $this->render('list.html.twig', $output);
}
更新:更新问题的答案基本相同,您需要做的就是将模板变量作为纯数组传递
return $this->render('list.html.twig', array_merge($output, ['table' => $table]));
或根据模板中的实际结构使用它们,例如{{ output.page }}
代替{{ page }}