Get url of file stored in page attribute
Permalink 1 user found helpful
Hi all,
I have some code in a 5.7 site, I'm trying to get the url of a PDF that my client will add via a page attribute:
Then later down the page, I have a print statement:
But this results in the error:
Object of class Concrete\Core\File\File could not be converted to string
How can I fix this please?
Thanks in advance
Dave
I have some code in a 5.7 site, I'm trying to get the url of a PDF that my client will add via a page attribute:
$pdfLink = $c->getAttribute('pdf_download'); $pdfLinkUrl = View::url('/download_file', $pdfLink, $c->getCollectionID());
Then later down the page, I have a print statement:
<?php print $pdfLinkUrl ?>
But this results in the error:
Object of class Concrete\Core\File\File could not be converted to string
How can I fix this please?
Thanks in advance
Dave
I believe the issue is $pdfLink in your example is a File object and not a string.
An alternative using URL:to()
An alternative using the File method getDownloadURL()
- this does the same thing as the above approach, with less code