setAttribute thumbnail programmatically
Permalink
Hi, I'm trying to set a thumbnail attribute programmatically. I have the attribute setup for the page - 'thumbnail' and I have the image uploaded into the filemanager and I know the ID of the image (in this case '235')...
I'm thinking that it's something along the line of:
but the finer points are eluding me...
Am I on the right track?
I'm thinking that it's something along the line of:
$newpage->setAttribute('thumbnail', $file->getFile()->getFileID());
but the finer points are eluding me...
Am I on the right track?
Depending upon what your $file variable is you are on the right track, you want to pass the File ID into the setAttribute function
That's the bit that's eluding me.... :)
What do I need to do to setup the $file variable?
Is that nearly right? :)
What do I need to do to setup the $file variable?
$file = **all I know is that the file is called logo.jpg and that it is in the filemanager with ID 235** $newpage->setAttribute('thumbnail', $file->getFile()->getFileID(235));
Is that nearly right? :)
If you just want to hard code that one id all you have to do is
$newpage->setAttribute('thumbnail', 235);
Brilliant! Once again, even simpler than I thought... I like to try and make things more difficult for myself!
Thanks for your help again mate!
Rob
Thanks for your help again mate!
Rob
Hrm, I got excited too soon... it doesn't seem to be doing it.
Is that all the info I need to put in? 'handle' & 'id'?
I can't think what else it would want from me...
Is that all the info I need to put in? 'handle' & 'id'?
I can't think what else it would want from me...
Yes, that is all the information you need. Are you sure that your $newpage variable is the correct page object?
Yeah, as I've just tagged that line onto the bottom of a whole load of other attributes that are set when the page is created... very strange
all the other attributes are being set
all the other attributes are being set
It wouldn't be anything to do with filemanager permissions would it? These pages are being created by a user (logged in but not accessing any dashboard stuff)
...although that wouldn't make much difference as they are able to create the page and add all the other attributes
...although that wouldn't make much difference as they are able to create the page and add all the other attributes
This shouldn't have anything to do with permissions, your "thumbnail" attribute is an image type attribute, right?
Ahahaha, I have sussed it out... finally...
I have to create a fileObject first... so instead of
I give it:
This then successfully sets the page image thumbnail
Yes!
I have to create a fileObject first... so instead of
$newpage->setAttribute('thumbnail', 235);
I give it:
$fObj = File::getByID(235); // setup file object based on fileID then: $newpage->setAttribute('thumbnail', $fObj); // then set the fileObject as the $tring
This then successfully sets the page image thumbnail
Yes!