【问题标题】:Symfony Entity Not Saving to the Database on PersistSymfony 实体不保存到持久化数据库
【发布时间】: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


【解决方案1】:

检查数据库,它可以保存,但如果'status_id'为空,它将不会显示在任何地方

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    相关资源
    最近更新 更多