Symfony Doctrine 2 и DateTime

lubasha

Новичок
Всем привет!
Есть модель
PHP:
/**
 * NewBundle\Adv\Entity\DailyBudgets
 *
 * @ORM\Table(name="table_bd")
 * @ORM\Entity
 */
class DailyBudgets
{
    /**
     * @[USER=4683]var[/USER] \DateTime $date
     * @ORM\Id
     * @ORM\Column(name="date", type="date", nullable=true)
     */
    private $date;

    /**
     * @[USER=4683]var[/USER] integer $campId
     * @ORM\Id
     * @ORM\Column(name="camp_id", type="integer", nullable=false)
     */
    private $campId;

    /**
     * @[USER=4683]var[/USER] integer $skrId
     * @ORM\Id
     * @ORM\Column(name="skr_id", type="integer", nullable=false)
     */
    private $skrId;

    /**
     * @[USER=4683]var[/USER] float $budget
     *
     * @ORM\Column(name="budget", type="float", nullable=false)
     */
    private $budget;

    /**
     * @[USER=4683]var[/USER] float $bid
     *
     * @ORM\Column(name="bid", type="float", nullable=false)
     */
    private $bid = 0;

    /**
     * @[USER=4683]var[/USER] integer $skrCampId
     * @ORM\Id
     * @ORM\Column(name="skr_camp_id", type="integer", nullable=false)
     */
    private $skrCampId  = 0;

    public function __construct($skrId, $campId, $skrCampId, $date)
    {
        $this->skrId = $skrId;
        $this->campId = $campId;
        $this->skrCampId = $skrCampId;
        $this->date = $date;
    }

    /**
     * Set date
     *
     * @param \DateTime $date
     */
    public function setDate($date)
    {
        $this->date = $date;
    }

    /**
     * @return \DateTime
     */
    public function getDate()
    {
        return $this->date;
    }

    /**
     * Set campId
     *
     * @param integer $campId
     */
    public function setCampId($campId)
    {
        $this->campId = $campId;
    }

    /**
     * Get campId
     *
     * @return integer
     */
    public function getCampId()
    {
        return $this->campId;
    }

    /**
     * Set skrCampId
     *
     * @param integer $skrCampId
     */
    public function setSkrCampId($skrCampId)
    {
        $this->skrCampId = $skrCampId;
    }

    /**
     * Get skrCampId
     *
     * @return integer
     */
    public function getSkrCampId()
    {
        return $this->skrCampId;
    }

    /**
     * Set skrId
     *
     * @param integer $skrId
     */
    public function setSkrId($skrId)
    {
        $this->skrId = $skrId;
    }

    /**
     * Get skrId
     *
     * @return integer
     */
    public function getSkrId()
    {
        return $this->skrId;
    }

    /**
     * Set budget
     *
     * @param float $budget
     */
    public function setBudget($budget)
    {
        $this->budget = $budget;
    }

    /**
     * Get budget
     *
     * @return float
     */
    public function getBudget()
    {
        return $this->budget;
    }

    /**
     * Set bid
     *
     * @param float $bid
     */
    public function setBid($bid)
    {
        $this->bid = $bid;
    }

    /**
     * Get bid
     *
     * @return float
     */
    public function getBid()
    {
        return $this->bid;
    }
}
Кода пытаюсь записать данные в таблицу

$date = new \DateTime('now');
$dateTo= $date->format('Y-m-d');

$dailyBudgets = new DailyBudgets(0, 12345, 0, $dateTo);

Получаю ошибку
Fatal error: Call to a member function format() on a non-object

Как исправить?
Модель писал впервые, может с ней что-то не так?
 

WMix

герр M:)ller
Партнер клуба
судя по данному описанию
PHP:
    /**
     * @[USER=4683]var[/USER] \DateTime $date
     * @ORM\Id
     * @ORM\Column(name="date", type="date", nullable=true)
     */
    private $date;

    public function __construct($skrId, $campId, $skrCampId, $date)
    {
        ...
        $this->date = $date;
    }
надо передавать готовый DateTime object
PHP:
$dailyBudgets = new DailyBudgets(x, y, z, new \DateTime('now'));
 

lubasha

Новичок
судя по данному описанию
PHP:
    /**
     * @[USER=4683]var[/USER] \DateTime $date
     * @ORM\Id
     * @ORM\Column(name="date", type="date", nullable=true)
     */
    private $date;

    public function __construct($skrId, $campId, $skrCampId, $date)
    {
        ...
        $this->date = $date;
    }
надо передавать готовый DateTime object
PHP:
$dailyBudgets = new DailyBudgets(x, y, z, new \DateTime('now'));
Тогда я получаю ошибку
Fatal Error: Object of class DateTime could not be converted to string
 

hell0w0rd

Продвинутый новичок
lubasha
а сделать var_dump объекта перед flush...
Доктрина принимает DateTime, а не строку
 
Сверху