2011-10-08 18 views
8

Próbuję dodać użytkownika do mojej bazy danych przez Doctrine 2.1 projektu i Dostaję taki rodzaj błędu:Doctrine 2.1 - Błąd w DateTimeType

Fatal error: Call to a member function format() on a non-object in C:...\Doctrine\DBAL\Types\DateTimeType.php on line 44

tabeli bazy danych sam stworzył bez żadnych problemów. Co może być nie tak z moim następującym kodem?

<?php 
/** 
* @Entity @Table(name="users") 
*/ 
class User { 
    /** 
    * @Id @GeneratedValue @Column(type="integer") 
    * @var string 
    */ 
    protected $id; 

    /** 
    * @Column(type="string", length=20, unique=TRUE) 
    * @var string 
    */ 
    protected $login; 

    /** 
    * @Column(type="string", length=50, nullable=TRUE) 
    * @var string 
    */ 
    protected $nickname; 

    /** 
    * @Column(type="string", length=50, nullable=TRUE) 
    * @var string 
    */ 
    protected $firstname; 

    /** 
    * @Column(type="string", length=50, nullable=TRUE) 
    * @var string 
    */ 
    protected $lastname; 

    /** 
    * @Column(type="string",length=100) 
    * @var string 
    */ 
    protected $email; 

    /** 
    * @Column(type="string",length=24) 
    * @var string 
    */ 
    protected $password; 

    /** 
    * @Column(type="string", length=50, nullable=TRUE) 
    * @var string 
    */ 
    protected $city; 

    /** 
    * @Column(type="date", nullable=TRUE) 
    * @var string 
    */ 
    protected $birth_date; 

    /** 
    * @Column(type="text", nullable=TRUE) 
    * @var string 
    */ 
    protected $description; 

    /** 
    * @Column(type="boolean") 
    * @var boolean 
    */ 
    protected $activation = FALSE; 

    /** 
    * @Column(type="datetime", nullable=TRUE) 
    */ 
    protected $registration_date; 

    /** 
    * @Column(type="datetime", nullable=TRUE) 
    */ 
    protected $login_date; 

    /** 
    * @Column(type="integer") 
    * @var integer 
    */ 
    protected $forum_posts_amount = 0; 

    /** 
    * @Column(type="integer", length=3) 
    * @var integer 
    */ 
    protected $forum_group = 0; 

    /** 
    * @Column(type="integer") 
    * @var integer 
    */ 
    protected $comments_amount = 0; 

    /** 
    * @Column(type="boolean") 
    * @var boolean 
    */ 
    protected $newsletter = FALSE; 

    public function __construct() { 
     $this->registration_date = date("Y-m-d H:i:s"); 
    } 

    public function getId() { return $this->id; } 

    public function getLogin() { return $this->login; } 
    public function setLogin($login) { $this->login = $login; } 

    public function getNickname() { return $this->nickname; } 
    public function setNickname($nickname) { $this->nickname = $nickname; } 

    public function getFirstname() { return $this->firstname; } 
    public function setFirstname($firstname) { $this->firstname = $firstname; } 

    public function getLastname() { return $this->lastname; } 
    public function setLastname($lastname) { $this->lastname = $lastname; } 

    public function getEmail() { return $this->email; } 
    public function setEmail($email) { $this->email = $email; } 

    public function getPassword() { return $this->password; } 
    public function setPassword($password) { $this->password = $password; } 

    public function getCity() { return $this->city; } 
    public function setCity($city) { $this->city = $city; } 

    public function getBirthDate() { return $this->birth_date; } 
    public function setBirthDate($birth_date) { $this->birth_date = $city; } 

    public function getDescription() { return $this->description; } 
    public function setDescription($description) { $this->description = $description; } 

    public function setLoginDate($login_date) { $this->login_date = $login_date; } 

    public function getForumGroup() { return $this->forum_group; } 
    public function setForumGroup($forum_group) { $this->forum_group = $forum_group; } 

    public function getCommentsAmount() { return $this->comments_amount; } 
    public function boostCommentsAmount() { $this->comments_amount++; } 

    public function getNewsletter() { return $this->newsletter; } 
    public function setNewsletter($newsletter) { $this->newsletter = $newsletter; } 
} 

Dzięki za pomoc z góry.

+0

możliwy duplikat [Doctrine 2.1 - datetime domyślną wartość kolumny] (http://stackoverflow.com/questions/7698625/doctrine-2-1-datetime-column-default- value) –

+0

Masz również błąd w 'setBirthDate()'. – FtDRbwLXw6

Odpowiedz

18

Doktryna wymaga date(time) kolumny zawierają DateTime obiektów. Więc w rzeczywistości twój konstruktor powinien przeczytać

public function __construct() { 
    $this->registration_date = new \DateTime(); 
} 
+0

Dzięki! To jest to! :) –

1

Jestem pewien, że to coś z __construct()

+1

Ale czy wiesz co, o? –

Powiązane problemy