[英]How do I debug a failing DB write with Doctrine and Symfony2?
In a controller I have this after a form is submitted and isValid()
在控制器中,提交表单和isValid()
之后,我有了这个
// ...
$em = $this->getDoctrine()->getEntityManager();
$em->persist($form->getData());
$em->flush();
// ...
I have checked the contents of $form->getData()
and it looks fine but it's not writing it to the table. 我已经检查了$form->getData()
的内容,它看起来不错,但是没有将其写入表中。 I'm not getting any errors in the logs. 我的日志中没有任何错误。 How can I start debugging this? 我该如何开始调试呢?
in my Entity class, which was for user registration I had a date created field. 在我的Entity类(用于用户注册)中,我有一个创建日期字段。 In order to populate this field I had 为了填充此字段,我有
// this is the WRONG version
class User{
//...
/**
* @ORM\Column(type="datetime")
*/
protected $created;
//...
public function __construct()
{
$this->created = date("Y-m-d H:i:s");
}
public function setCreated(\DateTime() $created)
{
$this->created = $created;
}
}
However what I should have had is: 但是我应该有的是:
/**
* ... other orm settings
* @ORM\HasLifecycleCallbacks()
*/
class User{
/**
* @ORM\Column(type="datetime")
*/
protected $created;
//....
/**
* @ORM\prePersist
*/
public function setCreatedValue()
{
$this->created = new \DateTime();
}
}
The reason I didn't spot this is that no error was logged to the log files. 我没有发现这一点的原因是没有错误记录到日志文件中。 I was submitting this form as an ajax call and didn't think to look in the response for that ajax call for the error until I turned on firebug (was relying on the default chrome console) 我将这个表单作为ajax调用提交,并且在我打开Firebug(依赖于默认的chrome控制台)之前,我不认为应该在该ajax调用的响应中查找错误。
I don't remember the exact error that can back but it was around the DateTimeType. 我不记得可以返回的确切错误,但它与DateTimeType有关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.