【发布时间】:2012-06-05 20:37:15
【问题描述】:
我在学说实体中有一个名为“生日”的字段。
我想创建一个对象以使用教义添加到数据库中。
在控制器内部:
$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;
}
【问题讨论】:
-
您能否向我们展示您与 Student 相关的实体?你检查了this answer 吗?
-
pastebin.com/8D7tdSef(我无法编辑帖子)
-
你检查this answer了吗? - 关于日期时间
标签: symfony doctrine doctrine-orm