我已经使用Symfonies生成了命令
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应用程序/控制台触发器构建Symfony给了我这个错误行。
有人能帮我一下,让这个命令对我有用吗?