$page->update()
Updates the page data
$page->update(array|null $input = null, string|null $languageCode = null, bool $validate = false): Kirby\Cms\Page
Parameters
Name | Type | Default |
---|---|---|
$input | array ornull |
null
|
$languageCode | string ornull |
null
|
$validate | bool |
false
|
Return type
This method does not modify the existing $page
object but returns a new object with the changes applied. Learn more →
Parent class
Examples
try {
$newPage = page('mypage')->update([
'title' => 'A new title',
'text' => 'Some text',
'anotherfield' => 'Some more data'
]);
echo 'The page has been updated:';
} catch(Exception $e) {
echo $e->getMessage();
}
Updating a field by callback
$newPage = $page->update([
'title' => function($title) {
return Str::lower($title);
}
]);
Multi-language site
Use the optional $lang
parameter to specify the language you want to update.
try {
$newPage = page('mypage')->update([
'title' => 'A new title',
'text' => 'Some text',
'anotherfield' => 'Some more data'
], 'en');
echo 'The page has been updated';
} catch(Exception $e) {
echo $e->getMessage();
}