【发布时间】:2018-02-07 21:48:41
【问题描述】:
我已经使用 Symfonys 生成了命令
php app/console generate:command
它生成了这个命令并添加了
class AppTriggerBuildCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('trigger')
->setDescription('...')
->addArgument('argument', InputArgument::OPTIONAL, 'Argument description')
->addOption('option', null, InputOption::VALUE_NONE, 'Option description')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$argument = $input->getArgument('argument');
if($argument == 'build'){
$content = $this->pageAction('en', 'home');
$this->storeContentElementsAction('en', 'home', $content);
}
$output->writeln('You are outside build.');
}
public function pageAction($language, $page) {
$akeneo = $this->getContainer()
->get("pimc.akeneo_cms.backend_connector");
$contentElements = $akeneo->getContentElementList($page);
$contentElements = $this->sort($contentElements);
$content = $this->getContainer()->get('templating')->renderResponse(
'AppBundle::page.html.twig',
["contentElements" => $contentElements, "language" => $language]);
return $content;
}
private function sort($contentElements) {
ksort($contentElements);
return $contentElements;
}
/**
* @param $language
* @param $page
*/
public function storeContentElementsAction($language, $page, \Symfony\Component\HttpFoundation\Response $content) {
$staticalContent = new StaticContent();
$staticalContent->setData($content->getContent());
$staticalContent->setBuild(1);
$staticalContent->setName("/".$language."/".$page.".html");
$doctrine = $this->getContainer()->get('doctrine');
$em = $doctrine->getManager();
$em->persist($staticalContent);
$em->flush();
}
}
StaticContent 是一个实体。
但是当我在命令行中调用这个命令时,我遇到了一个我无法解决的异常错误。 php app/console trigger build Symfony 给了我这个错误行。
有人可以帮助我让这个命令对我有用吗?
【问题讨论】:
-
将 renderResponse 改为 render。这将使您摆脱这个特定的错误。可能还有更多。
-
嗯,好的。我已将它从 renderResponse 更改为 render,但我仍然有同样的错误。我做错了什么?
标签: php symfony doctrine twig symfony-2.8