XF 2.0 Query to get the attachment URL from just the ID?

Mave

Active member
I auto generate html pages through php from certain nodes and threads. (don't worry, I use a read-only db user)
For embedded images I just replace the IMG bb codes with the html img tag.

But I recently started using attachments and the only data I get is
Code:
[ATTACH=full]24[/ATTACH]
Example: https://themavesite.com/pictures/ (scroll down for working embedded images)

Can anyone help me into getting the full image URL with just the ID?

Thanks in advance!
 
For a single attachment:

PHP:
$attachment = \XF::em()->find('XF:Attachment', $attachmentId);
$router = \XF::app()->router('public');
$link = $router->buildLink('attachments', $attachment);

If you have a lot on a page it's probably best to query them all at once (just pass an array of IDs in lieu of $attachmentId) and iterate over the entities to build the links.
 
Back
Top Bottom