我在學說實體中有一個名爲「生日」的字段。如何在Doctrine 2中設置日期?
我想創建一個對象來添加到數據庫使用原則。
控制器內部:
$name = "John Alex";
$birthday = "11-11-90";
$student = new Student();
$student->setName($name);
$student->setBirthday(strtotime($birthday);
...
但是當我試圖堅持我得到這個錯誤
Fatal error: Call to a member function format() on a non-object in /Library/WebServer/Documents/Symfony/vendor/doctrine-dbal/lib/Doctrine/DBAL/Types/DateType.php on line 44
編輯:
我的實體:
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var date $birthday
*
* @ORM\Column(name="birthday", type="date", nullable=true)
*/
private $birthday;
/**
* Set birthday
*
* @param date $birthday
*/
public function setBirthday($birthday)
{
$this->birthday = $birthday;
}
/**
* Get birthday
*
* @return date
*/
public function getBirthday()
{
return $this->birthday;
}
你能告訴我們你的有關學生的實體?你有沒有檢查[這個答案](http://stackoverflow.com/questions/7463137/saving-a-zend-date-in-the-database-with-doctrine-2-1)? – j0k
http://pastebin.com/8D7tdSef(我無法編輯線程) –
您是否檢查[此答案](http://stackoverflow.com/questions/7463137/saving-a-zend-date-in- the-database-with-doctrine-2-1)? - 關於DateTime – j0k