Php Symfony实体在持久化时未保存到数据库
这在控制器上有效,但在注入命令时不起作用Php Symfony实体在持久化时未保存到数据库,php,symfony,doctrine,entity,orocrm,Php,Symfony,Doctrine,Entity,Orocrm,这在控制器上有效,但在注入命令时不起作用 public function execute(InputInterface $input, OutputInterface $output) { $em = $this->getDoctrine()->getManager(); try { $task = new Task(); $task->setSubject("Test subject"); $task->
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将成功地拾取它,直到结束,但它不会抛出任何错误或保存实体。检查数据库,它可以保存,但如果“status\u id”为空,它将不会显示在任何地方。实体的配置是如何完成的?您是否检查了日志?它是否表示实体确实是持久化的?命令不是控制器。没有一种方法。从cron外部运行该命令以查看错误消息。然后查看文档,了解如何从容器中获取条令实体管理器。我看到您更新了问题以显示get条令方法。现在能用了吗?你在克朗之外试过吗?嘿@Cerad。是的,这样做没有任何错误。但它不保存所述实体。进一步挖掘。