[英]Symfony2, Doctrine - flush() returns format() error
I have a problem with saving data in database. 我在数据库中保存数据时遇到问题。 Doctrine command - flush() returns 主义命令-flush()返回
Error: Call to a member function format() on a non-object in /Users/magdalena/Sites/webping/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php line 53 错误:在/Users/magdalena/Sites/webping/vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/DateTimeType.php第53行中的非对象上调用成员函数format()
every time when I try to save it. 每当我尝试保存它时。 I checked date format many times. 我检查了日期格式很多次。 These are date which I would like to save: 这些是我要保存的日期:
$currentDate = new \DateTime('now');
which generate:
["date"]=> object(DateTime)#712 (3) {
["date"]=>
string(26) "2015-05-25 11:57:19.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Warsaw" }
What is wrong with it? 怎么了
This is the function which saving data: 这是保存数据的功能:
$this->setUserId($data['userId']);
$this->setPackageName($data['packageName']);
$this->setPackageId($data['packageId']);
$this->setUnitPrice($data['unitPrice']);
$this->setService($data['service']);
$this->setSms($data['sms']);
$this->setUpgrade(0);
$this->setDate($currentDate);
$this->setEndDate($data['endDate']);
$this->setPaymentType($data['paymentType']);
$this->setCompanyName($user['companyName']);
$this->setCity($user['city']);
$this->setAddress($user['address']);
$this->setPostalCode($user['postalCode']);
$this->setNip($user['nip']);
$this->setStatus(0);
$em = $em->getManager();
$em->persist($this);
$em->flush();
and data: 和数据:
$data:
array(10) {
["userId"]=>
int(287)
["packageName"]=>
string(8) "standard"
["packageId"]=>
int(7)
["sms"]=>
int(100)
["service"]=>
int(10)
["endDate"]=>
object(DateTime)#742 (3) {
["date"]=>
string(26) "2015-06-27 12:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Warsaw"
}
["unitPrice"]=>
string(5) "59.99"
["date"]=>
object(DateTime)#715 (3) {
["date"]=>
string(26) "2015-05-25 12:15:09.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Warsaw"
}
["upgrade"]=>
NULL
["paymentType"]=>
string(7) "przelew"
}
$user:
array(6) {
["companyName"]=>
string(8) "vdbfgbfg"
["address"]=>
string(5) "fgbfg"
["city"]=>
string(5) "bfgbf"
["postalCode"]=>
string(6) "23-098"
["nip"]=>
string(10) "1234563218"
["payment"]=>
string(7) "przelew"
}
EDIT 编辑
I've noticed that this error occurred every time when I flash() data in new code. 我注意到,每次在新代码中刷新()数据时都会发生此错误。 Even when I don't change any date. 即使我不更改任何日期。 Previous code works without errors. 先前的代码可以正常工作。 This may be related to cache? 这可能与缓存有关吗?
CurrentDate looks ok it is a DateTime object which will not be the problem, on the other hand $this->setEndDate($data['endDate']);
另一方面,CurrentDate看起来不错,它不是一个DateTime对象,另一方面, $this->setEndDate($data['endDate']);
this field i am not sure about which type is it but i am guessing this is your problem, otherwise show us your entity for more help. 我不确定该字段是哪种类型,但是我猜这是您的问题,否则请向我们显示您的实体以获取更多帮助。 and check your endDate if it is a DateTime object or just string. 并检查您的endDate是否为DateTime对象或只是字符串。
It started to work when I call $em->clear() before set new data and flush(). 当我在设置新数据和flush()之前调用$ em-> clear()时,它开始工作。 Is it a good way? 这是个好方法吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.