Hello guys i'm newbie on Symfony and making a web using sonata admin bundle. I wanted to add event on adesigns calendar bundle from sonata admin but when i extend EventEntity class and try to add new event, it gave me below error:
Type error: Argument 2 passed to AppBundle\Entity\Schedule::__construct() must be an instance of DateTime, none given, called in /path/to/project/vendor/sonata-project/doctrine-orm-admin-bundle/Model/ModelManager.php on line 509
I know it causes type of DateTime, but i don't know how to solve it.
Here's the extended code:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use ADesigns\CalendarBundle\Entity\EventEntity;
/**
* Schedule
*
* @ORM\Table(name="schedule")
* @ORM\Entity(repositoryClass="AppBundle\Repository\ScheduleRepository")
*/
class Schedule extends EventEntity {
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM\Column(name="title", type="string", length=255)
*/
protected $title;
/**
* @var string
* @ORM\Column(name="url", type="string", length=255, nullable=true)
*/
protected $url;
/**
* @var string
* @ORM\Column(name="bgColor", type="string", length=255)
*/
protected $bgColor;
/**
* @var string
* @ORM\Column(name="fgColor", type="string", length=255)
*/
protected $fgColor;
/**
* @var string
* @ORM\Column(name="cssClass", type="string", length=255, nullable=true)
*/
protected $cssClass;
/**
* @var bool
* @ORM\Column(name="allDay", type="boolean")
*/
protected $allDay;
/**
* @var DateTime
* @ORM\Column(name="startDatetime", type="datetime")
*/
protected $startDatetime;
/**
* @var DateTime
* @ORM\Column(name="endDatetime", type="datetime")
*/
protected $endDatetime;
public function __construct($title, \DateTime $startDatetime, \DateTime $endDatetime = null, $allDay = false, $hall) {
parent::__construct($title, $startDatetime, $endDatetime, $allDay);
$this->hall = $hall;
}
/**
* Get id
*
* @return int
*/
public function getId() {
return $this->id;
}
}
If you try to extend a Doctrine entity not designed for that you will encounter problems.
You should use an event listener or a subscriber class instead.