Embed multiple files in theme page type

Permalink
I'm using Tony's Multiple File Attribute (http://www.concrete5.org/marketplace/addons/multiple-files-attribute/) to attach several documents to a page type template. I would like to include links to those documents within the template. Using
echo $c->getAttribute('files')
returns a list of file IDs like: 1304,1303,1300,1298. So understandably something like
$c->getAttribute('files')->getVersion()->getRelativePath()
won't work for this. How can I parse these out into actual links?

hursey013
 
Remo replied on at Permalink Reply
Remo
are you sure it isn't an array?


$arr = $c->getAttribute('files');
foreach ($arr as $fID) {
  echo $fID;
}


I'd recommend using print_r instead of echo to get the complete structure of the object.
hursey013 replied on at Permalink Reply
hursey013
I had tried that, but when I do I get a PHP error: Warning: Invalid argument supplied for foreach()
hursey013 replied on at Permalink Reply
hursey013
When I do a print_r I get the same result: 1304,1303,1300,1298
Remo replied on at Permalink Reply
Remo
if he really outputs a string you have to split it and use something like File::getByID to get the actual object
Remo replied on at Permalink Best Answer Reply
Remo
he even created a method which does that for you.

MultipleFilesAttributeTypeController::getFiles
static public function getFiles($valueStr=''){  
      $files=array();
      foreach(explode(',',$valueStr) as $fID){
         if(!intval($fID)) continue;
         $file = File::getByID(intval($fID));
         if(!is_object($file) || !$file->getFileID()) continue;   
         $files[]=$file; 
      }     
      return $files; 
   }
hursey013 replied on at Permalink Reply
hursey013
Thanks Remo - I'll mess around with that.
lexbi replied on at Permalink Reply
Just tried to get this going myself, did the following

$page = Page::getCurrentPage();
$images = $page->getAttribute('files');
$getFiles = MultipleFilesAttributeTypeController::getFiles($images);
foreach($getFiles as $file){
   echo $file->getVersion()->getRelativePath();
}