【发布时间】:2016-05-12 08:45:25
【问题描述】:
这适用于控制器,但在注入命令时不起作用。
public function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getDoctrine()->getManager();
try {
$task = new Task();
$task->setSubject("Test subject");
$task->setCreatedAt(new \DateTime());
$em->persist($task);
$em->flush();
} catch (\Exception $e) {
throw $e; //no error
}
//prints successful here
}
/**
* @param string $entityName
* @return \Doctrine\Common\Persistence\ObjectRepository
*/
protected function getRepository($entityName)
{
return $this->getDoctrine()->getRepository($entityName);
}
protected function getDoctrine()
{
return $this->getContainer()->get('doctrine');
}
cron 成功地将其拾取直到结束,但它不会抛出任何错误或保存实体。
【问题讨论】:
-
实体的配置是怎么做的?
-
你检查过日志吗?它是否说实体确实是持久的?
-
命令不是控制器。没有 getDoctrine 方法。从 cron 外部运行命令以查看错误消息。然后查看文档以了解如何从容器中获取学说实体管理器。
-
我看到您更新了问题以显示 getDoctrine 方法。它现在有效吗?您是否从 cron 外部尝试过?
-
嘿@Cerad。是的,这没有任何错误。除了它不保存所述实体。进一步挖掘。
标签: php symfony doctrine entity orocrm