Cannot access protected property Concrete\Core\File\File::$fID

Permalink
Hi there,

I want to place a background on my page, comming from an attribute. <5.7 I did it with the following code:
<?php 
$c = Page::getCurrentPage();
$pl = $c->getCollectionAttributeValue('achtergrond');
   $pv       = File::getByID($pl->fID);
   if (empty($pl)) {
    $image_url    = $this->getThemePath()."/images/banner.png";
   } else {
   $image_url    = $pv->getRelativePath();
}
       ?>

Now I get the error

Cannot access protected property Concrete\Core\File\File::$fID

Does anybody know what to do? Thanks!

annekeh
View Replies: View Best Answer
Mainio replied on at Permalink Reply
Mainio
Change
$pl->fID


to:
$pl->getFileID();
Mainio replied on at Permalink Best Answer Reply
Mainio
Although, I'm not sure whether you even need that.

Your example does not specifically explain what type of an attribute the 'achterground' is but if it's already a file attribute, the line that says:
$pv = File::getByID($pl->fID);


is completely unnecessary.

You could use the $pl variable straight away if it's already a File object.
annekeh replied on at Permalink Reply
annekeh
Yes it is a file attribute. 'achtergrond' is dutch for 'background'. The following code is working like a charm:

$pl = $c->getCollectionAttributeValue('achtergrond');
   if (empty($pl)) {
    $image_url    = $this->getThemePath()."/images/banner.png";
   } else {
   $image_url    = $pl->getRelativePath();
}


So thanks a lot!
MichaelG replied on at Permalink Reply
MichaelG
AFAIK, you even don't need to define $c (if you're on a theme).
But yeah, mainio is correct. If the page attribute is a file type, then you have the image object already, and you can get the the relative url straight off of it.