i am having troubles with datetime attribute in my class.
Next code is in my twig template.
<div class="process-photo"><img src="{{ photo.getPhotoUrl }}" /></div>
This is the getPhotoUrl method
public function getPhotoUrl()
{
return '/web/uploads/photos/'.$this->getUserId().'/'.$this->getPhotoUploadDate().'/'.$this->getName();
}
This is the getPhotoUploadDate method
public function getPhotoUploadDate() {
return date('Y-m-d', strtotime($this->creationDate));
}
I am getting next error - Warning: strtotime() expects parameter 1 to be string, object given
If i try this way
public function getPhotoUrl()
{
return '/web/uploads/photos/'.$this->getUserId().'/'.$this->creationDate.'/'.$this->getName();
}
I am getting next error - Catchable Fatal Error: Object of class DateTime could not be converted to string
what i am doing wrong??
Object of class DateTime could not be converted to stringis all the information you need.$this->creationDateis an DateTime object, so instead ofdate('Y-m-d', strtotime($this->creationDate))you could easily$this->creationDate->format('Y-m-d'). Why would you create a date from a date you already have?