Pagefiles is a type of WireArray that contains Pagefile objects. It also acts as the value for multi-file fields in ProcessWire.
The items in a Pagefiles array are Pagefile
objects, indexed by file basename, i.e. myfile.pdf
. Information on most traversal, filtering and manipulation methods can be found in the WireArray
class that Pagefiles extends. In the examples below, $page->files
is an instance of Pagefiles:
// Determining if any files are present
if($page->files->count()) {
// There are files here
}
// Traversing and outputting links to all files
foreach($page->files as $name => $pagefile) {
echo "<li><a href='$pagefile->url'>$name: $pagefile->description</a></li>";
}
// Adding new file(s)
$page->files->add('/path/to/file.pdf');
$page->files->add('http://domain.com/photo.png');
$page->save('files');
// Getting file by name
$pagefile = $page->files->getFile('file.pdf');
$pagefile = $page->files['file.pdf']; // alternate
// Getting first and last file
$pagefile = $page->files->first();
$pagefile = $page->files->last();
Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Pagefiles
class also inherits all the methods and properties of: WireArray and Wire.
Common
Manipulation
Name | Return | Summary | |
---|---|---|---|
Pagefiles::add() Pagefiles::add($item) Pagefiles::add($item) | $this | Add a new Pagefile item or filename | |
Pagefiles::delete() Pagefiles::delete($item) Pagefiles::delete($item) | $this | Delete a pagefile item | |
Pagefiles::deleteAll() Pagefiles::deleteAll() Pagefiles::deleteAll() | $this | Delete all files associated with this Pagefiles instance, leaving a blank Pagefiles instance. | |
Pagefiles::rename() Pagefiles::rename(Pagefile $item, string $name) Pagefiles::rename(Pagefile $item, string $name) | Pagefiles | Queue a rename of a Pagefile |
Tags
Name | Return | Summary | |
---|---|---|---|
Pagefiles::findTag() Pagefiles::findTag($tag) Pagefiles::findTag($tag) | Pagefiles | Return all Pagefile objects that have the given tag(s). | |
Pagefiles::getTag() Pagefiles::getTag(string $tag) Pagefiles::getTag(string $tag) | Pagefile null | Return the first Pagefile that matches the given tag or NULL if no match | |
Pagefiles::tags() Pagefiles::tags() Pagefiles::tags($value = null) | string array Pagefiles | Get list of tags for all files in this Pagefiles array, or return files matching given tag(s) |
Other
Additional methods and properties
In addition to the methods and properties above, Pagefiles also inherits the methods and properties of these classes:
API reference based on ProcessWire core version 3.0.236