0

When I change the datatime with Sonata, it returns the error:

DateTime::__construct() expects parameter 1 to be string, object given

This is my entity:

public function setExpiry($dateAsString = null) {
   $this->expiry = new \DateTime($dateAsString);         
} 

Why am I getting this error?

Ben
  • 51,770
  • 36
  • 127
  • 149
Popolitus
  • 452
  • 1
  • 6
  • 21

1 Answers1

1

change the setter like this, because sonata calling it with a DateTime object paramter

public function setExpiry(\DateTime $datetime){
    $this->expiry = $datetime;
}
five
  • 276
  • 3
  • 4