If you want to create a list of media within a certain folder, you can use the getMediaList()
method. This method gets all the files and folder from the media library within the specified folder, including file link and alt.
Let's assume we want to create an overview of all documents (.pdf, .docx, etc.) for a specific product or service.
In our media library we well add a folder documents
and within that folder we will create the folder productA
. Within the productA folder we will add all documents belonging to that specific product (ie. manuals, waranty docs, etc.).
Now when we want to create a nice overview of these documents, in you view/section file, paste this code:
<?php
$documents = $webigniter->getMediaList(folderName: 'documents/productA');
foreach($documents['files'] as $document):?>
<a href="<?=$document['link'];?>"><?=$document['alt'];?></a>
<?php endforeach;?>
This will create a list of links to all the files within the documents/productA
folder in the media library. So if you add documents to this specific folder, they will automaticly be added to this page. Note that the files are in $documents['files']
, subfolders of the specified folder are in the array $documents['folders']
.
Next to the parameter folderName
, there are some more parameters you can use:
fileOrderType
: can be set to 'RAND' if you want to have a list in a random order.fileLimit
: can be used to limit the number of results (must be a valid integer).fileLimitOffset
: can be used to specify the offset of the results, usefull for pagination purposes.showFolders
: when set to true, folders are returned as well. (default is false)folderOrderType
: can be set to 'RAND' if you want to have a list in a random order.folderLimit
: can be used to limit the number of results (must be a valid integer).folderLimitOffset
: can be used to specify the offset of the results, usefull for pagination purposes.This method returns an array with 2 keys: files
and folders
, in the example above we only have files, because showFolders
was not set to true
.
The files array itself holds 2 array keys: link
and alt
.
The folders array holds 3 array keys: name
, description
and fileCount
.
This helper method can also be very usefull for creating image galleries for example..