File::create()
Creates a new file on disk and returns the File object. The store is used to handle file writing, so it can be replaced by any other way of generating files.
File::create(array $props): Kirby\Cms\File
Parameters
Name | Type | Default |
---|---|---|
$props * | array |
– |
Return type
Exceptions
Type | Description |
---|---|
Kirby\Exception\InvalidArgumentException |
|
Kirby\Exception\LogicException |
Parent class
$props
parameter
Name | Type | Description |
---|---|---|
blueprint | array |
Sets the Blueprint object |
content | array |
Sets the Content object |
filename * | string |
Sets the filename |
parent | Kirby\Cms\Model |
Sets the parent model object; this property is required for File::create() andwill be generally required starting with Kirby 3.7.0 |
root | string |
Always set the root to null, to invoke auto root detection |
source * | string |
source thingy |
template | string |
|
translations | array |
Create the translations collection from an array |
url | string |
Sets the url |
Creating a Kirby\Cms\File
without a parent property has been deprecated and throws a warning. Starting in 3.7.0 the property will be required and cause a breaking error if not passed.
Example
$file = File::create([
'source' => kirby()->root('assets').'/images/some-image.jpg',
'parent' => page('photography')->children()->listed()->first(),
'filename' => 'new-image.jpg',
'template' => 'cover',
'content' => [
'caption' => 'A nice view from above',
]
]);