2

这适用于控制器,但是,当注入命令时它不起作用。

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 成功地将其拾取直到结束,但它不会引发任何错误或保存实体。

4

1 回答 1

0

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

于 2020-03-05T19:31:24.183 回答