Symfony – Object of class DateTime could not be converted to string

i am having troubles with datetime attribute in my class.

Next code is in my twig template.

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??

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s