### Get Dropdown Option Setup
Source: https://getkirby.com/docs/reference/objects/panel/model/dropdown-option
Use this method to get the setup for dropdown options, typically for the changes dropdown. It modifies the existing model object and returns it.
```php
$model->dropdownOption(): array
```
--------------------------------
### GET Request Example
Source: https://getkirby.com/docs/reference/objects/http/remote/request
Demonstrates a basic GET request to fetch an image and save it to a file. Ensure the response code is 200 before writing content.
```php
children()->first();
$response = Remote::request(
'https://picsum.photos/200/300',
[
'method' => 'GET',
]
);
// Save content from request to file
if ($response->code() === 200) {
F::write($targetPage->root() . '/photo.jpg', $response->content());
}
```
--------------------------------
### Version Examples
Source: https://getkirby.com/docs/reference/objects/content/version
Examples demonstrating how to use the Version class to get unsaved changes and check for version existence in specific languages.
```APIDOC
## Examples
### Get all unsaved changes of a page
```php
// get all unsaved changes of page
$version = $page->version('changes');
```
### Check if changes exist in a particular language
```php
// check if changes exist in a particular language
$version->exists('de');
$version->exists('current');
$version->exists('default');
```
```
--------------------------------
### Install Git using RUN in Dockerfile
Source: https://getkirby.com/docs/cookbook/development-deployment/kirby-meets-docker
The RUN instruction executes commands in a new layer on top of the current image. This example updates package lists and installs Git, which is necessary for cloning repositories.
```dockerfile
RUN apt-get update && apt-get install -y git
```
--------------------------------
### Create New Kirby Project with Starterkit
Source: https://getkirby.com/docs/guide/install-guide/composer
Use this command to set up a new Kirby installation with the Starterkit using Composer.
```bash
composer create-project getkirby/starterkit your-project
```
--------------------------------
### Get Languages Root
Source: https://getkirby.com/docs/reference/system/roots/languages
Retrieves the root directory of the languages folder. No setup is required if using the default Kirby installation.
```php
= $kirby->root('languages') ?>
```
--------------------------------
### Install Starterkit via Kirby CLI
Source: https://getkirby.com/docs/guide/quickstart
Install the Starterkit using the Kirby Command Line Interface. You will be prompted to specify a folder name.
```bash
kirby install:kit Starterkit
```
--------------------------------
### Get Site Root in Kirby
Source: https://getkirby.com/docs/reference/system/roots/site
Use this method to retrieve the absolute path to the site folder. No setup is required if using the default Kirby installation.
```php
= $kirby->root('site') ?>
```
--------------------------------
### Get Kirby Models Root
Source: https://getkirby.com/docs/reference/system/roots/models
Use this method to retrieve the absolute path to the models folder. No setup is required if using default Kirby installation.
```php
= $kirby->root('models') ?>
```
--------------------------------
### Field::setup() Method
Source: https://getkirby.com/docs/reference/objects/form/field/setup
Loads all options from the component definition, mixes in defaults, and injects additional mixins.
```APIDOC
## Field::setup()
### Description
Loads all options from the component definition mixes in the defaults from the defaults method and then injects all additional mixins, defined in the component options.
### Method
static `setup`
### Signature
```php
Field::setup(string $type): array
```
### Parameters
#### Path Parameters
- **type** (string) - Required - The type of the field to set up.
### Return type
`array`
### Parent class
`Kirby\Form\Field` inherited from `Kirby\Toolkit\Component`
```
--------------------------------
### Get Config Folder Root
Source: https://getkirby.com/docs/reference/system/roots/config
Use this method to retrieve the absolute path to the config folder. No setup is required if using default Kirby installation.
```php
= $kirby->root('config') ?>
```
--------------------------------
### Section::setup() Method
Source: https://getkirby.com/docs/reference/objects/cms/section/setup
The Section::setup() method loads options, merges defaults, and injects additional mixins from component options.
```APIDOC
## Section::setup()
### Description
Loads all options from the component definition mixes in the defaults from the defaults method and then injects all additional mixins, defined in the component options.
### Method
`Section::setup(string $type): array`
### Parameters
#### Path Parameters
- **$type** (string) - Required - The type of the section.
### Return type
`array`
### Parent class
`Kirby\Cms\Section` inherited from `Kirby\Toolkit\Component`
```
--------------------------------
### Instantiate Visitor Class
Source: https://getkirby.com/docs/reference/objects/http/visitor
Create a new instance of the Visitor class to begin inspecting visitor details. No specific setup is required beyond having Kirby installed.
```php
new Visitor()
```
--------------------------------
### Get All Started Database Instances
Source: https://getkirby.com/docs/reference/objects/database/database/instances
Use this method to retrieve an array of all currently active database instances. No setup is required beyond having a Database object.
```php
Database::instances(): array
```
--------------------------------
### Component::setup()
Source: https://getkirby.com/docs/reference/objects/toolkit/component/setup
Loads all options from the component definition, mixes in the defaults from the defaults method, and then injects all additional mixins defined in the component options.
```APIDOC
## Component::setup()
### Description
Loads all options from the component definition mixes in the defaults from the defaults method and then injects all additional mixins, defined in the component options.
### Method
```php
Component::setup(string $type): array
```
### Parameters
#### Path Parameters
- **$type** (string) - Required - The type of the component to set up.
### Return type
`array`
### Parent class
`Kirby\Toolkit\Component`
```
--------------------------------
### Get Kirby Core Root
Source: https://getkirby.com/docs/reference/system/roots/kirby
Use this method to retrieve the absolute path to the Kirby core folder. No setup is required if using the default Kirby installation.
```php
= $kirby->root('kirby') ?>
```
--------------------------------
### $system->init() Method
Source: https://getkirby.com/docs/reference/objects/cms/system/init
Initializes the Kirby system by creating necessary folders if they do not already exist.
```APIDOC
## $system->init()
### Description
Creates the most important folders if they don't exist yet.
### Method
`void`
### Endpoint
N/A (This is a method call, not an HTTP endpoint)
### Exceptions
#### `Kirby\Exception\PermissionException`
Thrown when the system lacks the necessary permissions to create folders.
### Parent class
`Kirby\Cms\System`
```
--------------------------------
### Section::setup() Method Signature
Source: https://getkirby.com/docs/reference/objects/cms/section/setup
This is the method signature for Section::setup(). It takes a string type as a parameter and returns an array.
```php
Section::setup(string $type): array
```
--------------------------------
### Get Constructor Start Line
Source: https://getkirby.com/docs/reference/objects/reflection/constructor/get-start-line
Use this method to retrieve the starting line number of the constructor. Available since Kirby 5.2.0.
```php
$constructor->getStartLine()
```
--------------------------------
### Load Starterkit Content and Set Permissions
Source: https://getkirby.com/docs/cookbook/development-deployment/git-based-deployment-with-dokku
Download the Kirby starterkit, extract its content, and copy it to the persistent storage directories for both live and dev applications on the server. Correct ownership and permissions are crucial for the application to access the content.
```bash
# SERVER (as root)
cd ~
wget -O starterkit.zip https://github.com/getkirby/starterkit/archive/refs/heads/main.zip
unzip starterkit.zip
cp -a starterkit-main/content/* /var/lib/dokku/data/storage/live/content/
cp -a starterkit-main/content/* /var/lib/dokku/data/storage/dev/content/
chown -R 32767:32767 /var/lib/dokku/data/storage/live/content
chown -R 32767:32767 /var/lib/dokku/data/storage/dev/content
rm -r starterkit-main starterkit.zip
```
--------------------------------
### Initialize Composer Project
Source: https://getkirby.com/docs/cookbook/headless/headless-getting-started
Use this command to start a new PHP project with Composer.
```bash
composer init
```
--------------------------------
### Setup Kirby Component
Source: https://getkirby.com/docs/reference/objects/toolkit/component
The `Component::setup()` static method is available for component setup. Its specific parameters or return values are not detailed.
```php
Component::setup()
```
--------------------------------
### Get Kirby Database Instance
Source: https://getkirby.com/docs/reference/objects/database/database/instance
Use this method to retrieve a started database instance. An optional ID can be provided to get a specific instance.
```php
Database::instance(string|null $id = null): Kirby\Database\Database|null
```
--------------------------------
### Full Example with Tabs and Columns
Source: https://getkirby.com/docs/guide/blueprints/layout
A comprehensive blueprint example demonstrating the use of tabs to organize content into 'Content' and 'SEO' sections. Each tab contains columns with fields and sections for detailed content management.
```yaml
title: My blueprint
tabs:
# content tab
content:
label: Content
icon: text
columns:
# main
main:
width: 2/3
sections:
# a simple form
content:
type: fields
fields:
headline:
label: Headline
type: text
text:
label: Text
type: textarea
# sidebar
sidebar:
width: 1/3
sections:
# a list of subpages
pages:
type: pages
label: Subpages
# a list of files
files:
type: files
label: Files
# seo tab
seo:
label: SEO
icon: search
fields:
seoTitle:
label: SEO Title
type: text
seoDescription:
label: SEO Description
type: text
```
--------------------------------
### Get Translations from Offset
Source: https://getkirby.com/docs/reference/objects/cms/translations/offset
Use this method to get a new Translations object starting from a specific index. The original object remains unchanged.
```php
$translations->offset(int $offset): Kirby\Cms\Translations
```
--------------------------------
### Create Dockerfile for Kirby Starterkit
Source: https://getkirby.com/docs/cookbook/development-deployment/kirby-meets-docker
This Dockerfile sets up an environment with PHP and Apache, clones the Kirby Starterkit, and prepares it for building a Docker image. It uses a pre-built image from Docker Hub as a base.
```dockerfile
FROM webdevops/php-apache-dev:8.1
RUN apt-get update && apt-get install -y git
RUN git clone --depth 1 https://github.com/getkirby/starterkit.git /app
```
--------------------------------
### Get Layouts from Offset
Source: https://getkirby.com/docs/reference/objects/cms/layouts/offset
Use the offset() method to get a new Layouts object starting from a specific index. This method does not alter the original object.
```php
$layouts->offset(int $offset): Kirby\Cms\Layouts
```
--------------------------------
### Get Fieldsets from Offset
Source: https://getkirby.com/docs/reference/objects/cms/fieldsets/offset
Use the offset() method to get a new Fieldsets object starting from a specific index. The original object remains unchanged.
```php
$fieldsets->offset(int $offset): Kirby\Cms\Fieldsets
```
--------------------------------
### Field::setup() Method Signature
Source: https://getkirby.com/docs/reference/objects/form/field/setup
This method loads options from the component definition, merges defaults, and injects mixins. It requires a string type parameter and returns an array.
```php
Field::setup(string $type): array
```
--------------------------------
### Get Blocks from Offset
Source: https://getkirby.com/docs/reference/objects/cms/blocks/offset
Use the offset() method to get a new Blocks object starting from a specific index. This method does not modify the original object.
```php
$blocks->offset(int $offset): Kirby\Cms\Blocks
```
--------------------------------
### Create Table Example
Source: https://getkirby.com/docs/reference/objects/aliases/database
Example demonstrating how to create a new table using the `createTable` method.
```APIDOC
## POST /database/createTable
### Description
Creates a new table in the database with the specified schema.
### Method
POST
### Endpoint
`/database/createTable`
### Parameters
#### Request Body
- **tableName** (string) - Required - The name of the table to create.
- **schema** (array) - Required - An associative array defining the table schema.
- **columnName** (array) - Required - Defines a column with its properties.
- **type** (string) - Required - The data type of the column (e.g., 'id', 'varchar', 'int', 'decimal').
- **size** (integer) - Optional - The size for string types.
- **unsigned** (boolean) - Optional - Whether the integer column should be unsigned.
- **precision** (integer) - Optional - The total number of digits for decimal types.
- **decimal_places** (integer) - Optional - The number of digits after the decimal point for decimal types.
### Request Example
```json
{
"tableName": "product",
"schema": {
"id": {"type": "id"},
"code": {"type": "varchar", "size": 50},
"description": {"type": "varchar"},
"quantity": {"type": "int", "unsigned": false},
"price": {"type": "decimal", "precision": 12, "decimal_places": 4}
}
}
```
### Response
#### Success Response (200)
- **status** (string) - Indicates the success of the operation (e.g., 'success').
- **message** (string) - A confirmation message.
#### Response Example
```json
{
"status": "success",
"message": "Table 'product' created successfully."
}
```
```
--------------------------------
### Start DDEV Project
Source: https://getkirby.com/docs/cookbook/development-deployment/ddev
After initializing the project, use this command to start the DDEV environment. This spins up the necessary Docker containers for your project.
```bash
ddev start
```
--------------------------------
### Instantiate GdLib Driver
Source: https://getkirby.com/docs/reference/objects/image-darkroom/gd-lib
Create a new instance of the GdLib darkroom driver. No specific setup is mentioned.
```php
new GdLib()
```
--------------------------------
### Starts With String Validation
Source: https://getkirby.com/docs/guide/blueprints/fields
Use the `startsWith` validator to enforce that the input value begins with a specific string. This example requires the value to start with 'AB-'.
```yaml
text:
type: text
validate:
startsWith:
AB-
```
--------------------------------
### Get Current Version
Source: https://getkirby.com/docs/reference/objects/cms-system/update-status/current-version
Retrieves the currently installed version of Kirby.
```APIDOC
## Get Current Version
### Description
Returns the currently installed version of the Kirby CMS.
### Method
```php
$updateStatus->currentVersion()
```
### Endpoint
N/A (This is a class method, not an API endpoint)
### Parameters
None
### Request Body
None
### Response
#### Success Response (200)
- **version** (string|null) - The currently installed version string, or null if not available.
#### Response Example
```json
{
"version": "3.8.0"
}
```
#### Error Response
None explicitly defined for this method.
```
--------------------------------
### Standard Object Instantiation
Source: https://getkirby.com/docs/cookbook/php/understanding-oop
This example shows the standard way to instantiate an object using the 'new' keyword and then call a method on it. It is presented for comparison with the static instantiation method.
```php
$title = (new Book('Form Design Patterns', 'Adam Silver'))->getTitle();
```
--------------------------------
### Initialize ImageMagick with Settings
Source: https://getkirby.com/docs/reference/objects/image-darkroom/image-magick/__construct
Use this constructor to initialize the ImageMagick darkroom driver with optional settings. The `$settings` parameter accepts an array of configuration options.
```php
new ImageMagick(array $settings = [ ])
```
--------------------------------
### $session->startTime()
Source: https://getkirby.com/docs/reference/objects/session/session/start-time
Gets the session start time as a Unix timestamp.
```APIDOC
## $session->startTime()
### Description
Gets the session start time.
### Method
This is a method of the Kirby\Session\Session class.
### Endpoint
N/A (Object method)
### Parameters
This method does not accept any parameters.
### Request Example
```php
$startTime = $session->startTime();
```
### Response
#### Success Response (int)
- **timestamp** (int) - The Unix timestamp of when the session started.
#### Response Example
```json
1678886400
```
### Parent Class
`Kirby\Session\Session`
```
--------------------------------
### Get Fields Object from Offset
Source: https://getkirby.com/docs/reference/objects/form/fields/offset
Use the offset method to get a new Fields object starting from a specific index. This method does not modify the original object.
```php
$fields->offset(int $offset): Kirby\Form\Fields
```
--------------------------------
### Example Docker Image List Output
Source: https://getkirby.com/docs/cookbook/development-deployment/kirby-meets-docker
This is an example output of the 'docker images' command, showing the repository name, tag, image ID, creation time, and size of local Docker images.
```text
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-starterkit latest afcbcc660571 14 seconds ago 1.14GB
```
--------------------------------
### Get String Between Two Delimiters
Source: https://getkirby.com/docs/reference/objects/toolkit/str/between
Use Str::between() to extract content between the first occurrence of a start and end string. Ensure both start and end strings are provided.
```php
Str::between(string|null $string, string $start, string $end): string
```
--------------------------------
### Run Kirby Starterkit Docker Container
Source: https://getkirby.com/docs/cookbook/development-deployment/kirby-meets-docker
Starts a Docker container from the 'docker-starterkit' image, mapping host port 80 to container port 80 and naming the container 'mycontainer'. Use this to launch the Kirby Starterkit locally.
```bash
docker run --name mycontainer -p 80:80 docker-starterkit
```
--------------------------------
### Get Kirby Versions from Offset
Source: https://getkirby.com/docs/reference/objects/content/versions/offset
Use the offset() method to get a new Kirby\Content\Versions object starting from a specified integer index. This method does not alter the original object.
```php
$versions->offset(int $offset): Kirby\Content\Versions
```
--------------------------------
### Create New Kirby Project with Plainkit
Source: https://getkirby.com/docs/guide/install-guide/composer
Alternatively, use this command to set up a new Kirby installation with the Plainkit using Composer.
```bash
composer create-project getkirby/plainkit your-project
```
--------------------------------
### Instantiate Exif Class
Source: https://getkirby.com/docs/reference/objects/image/exif
Create a new instance of the Exif class. This is the basic setup before accessing EXIF data.
```php
new Exif()
```
--------------------------------
### Remote::request() - API Examples
Source: https://getkirby.com/docs/reference/objects/http/remote/request
Examples demonstrating how to use Remote::request() for interacting with the Kirby API, including GET, POST, PATCH, and DELETE operations with authentication.
```APIDOC
## Kirby API Examples
Note: For these API examples to work, HTTP Basic auth must be enabled in your Kirby config. If testing locally without HTTPS, set the `allowInsecure` config option to `true`.
### GET Request
```php
'GET',
'headers' => [
'Authorization: Basic ' . base64_encode($email . ':' . $password)
],
]);
if ($response->code() === 200) {
$data = json_decode($response->content())->data;
dump($data);
}
?>
```
### POST Request
```php
Str::slug(Str::random(10, 'alpha')),
'template' => 'note',
'model' => 'note',
'isDraft' => false,
'content' => [
'title' => Str::random(40, 'alpha'),
]
];
$request = Remote::request('https://yoursite.com/api/pages/notes/children', [
'method' => 'POST',
'headers' => [
'Content-Type: application/json',
'Authorization: Basic ' . base64_encode($email . ':' . $password)
],
'data' => json_encode($data),
]);
if ($request->code() !== 200) {
echo 'An error occurred: ' . $request->code();
}
?>
```
### PATCH Request
```php
Str::random(40, 'alpha'),
];
$response = Remote::request('https://yoursite.com/api/pages/notes+exploring-the-universe', [
'method' => 'PATCH',
'headers' => [
'Content-Type: application/json',
'Authorization: Basic ' . base64_encode($email . ':' . $password)
],
'data' => json_encode($data),
]);
dump($response);
?>
```
### DELETE Request
```php
'DELETE',
'headers' => [
'Authorization: Basic ' . base64_encode($email . ':' . $password)
],
]);
dump($response);
?>
```
```
--------------------------------
### Get a slice of users
Source: https://getkirby.com/docs/reference/objects/cms/users/slice
Use the $users->slice() method to get a subset of users. Specify the starting offset and an optional limit. This method returns a new Users object.
```php
$users->slice(int $offset = 0, int|null $limit = null): Kirby\Cms\Users
```
--------------------------------
### PHP - Initialize and Require Class
Source: https://getkirby.com/docs/cookbook/php/understanding-oop
Sets up PHP error display and requires the Book class file. Ensure the Book.php file is in the same directory.
```php
slice(int $offset = 0, int|null $limit = null): Kirby\Cms\Layouts
```
--------------------------------
### Instantiate Site Model
Source: https://getkirby.com/docs/reference/objects/panel/site
Demonstrates how to create a new instance of the Site model. This is typically used to access site-related properties and methods.
```php
new Site()
```
--------------------------------
### Getting the URL of a File Thumbnail
Source: https://getkirby.com/docs/guide/read-me
This example demonstrates how to get the URL of a file's thumbnail. The `thumb()` method can return different object types, but `url()` is commonly used.
```php
= $file->thumb()->url() ?>
```
--------------------------------
### Create New Kirby Starterkit with DDEV
Source: https://getkirby.com/docs/cookbook/development-deployment/ddev
Combines DDEV configuration and starting with Composer to create a new Kirby Starterkit project. Be cautious as this command overwrites existing content in the directory.
```bash
ddev config --php-version=8.3 --omit-containers=db
ddev start
ddev composer create getkirby/starterkit
ddev launch
```
--------------------------------
### Setting up a basic form
Source: https://getkirby.com/docs/reference/objects/form/form
Instantiate a new Form object with a defined set of fields. Each field can have a label and type.
```php
use Kirby\Form\Form;
$form = new Form(
fields: [
'name' => [
'label' => 'Name',
'type' => 'text'
],
'email' => [
'label' => 'Email',
'type' => 'email'
],
'message' => [
'label' => 'Message',
'type' => 'textarea'
]
]
);
```
--------------------------------
### Get the number of languages
Source: https://getkirby.com/docs/reference/objects/cms/languages
Returns the total count of languages defined in the Kirby installation.
```APIDOC
## Get the number of languages
Returns the total count of languages defined in the Kirby installation.
```php
$numberOfLanguage = $languages->count();
```
```
--------------------------------
### Get Default Language Object
Source: https://getkirby.com/docs/reference/objects/cms/language
Retrieve the default language object for the Kirby installation.
```php
$language = $kirby->defaultLanguage();
```
--------------------------------
### Full Template with $site Variables
Source: https://getkirby.com/docs/guide/templates/collections---Examples%3A%60%60%60php%3C?php%24customCollection+=+collection%28%27projects%27%29%3Bdump%28%24customCollection%29%3B%60%60%60
A comprehensive template example demonstrating the use of `$site->title()`, `$site->description()`, `$site->url()`, and `$site->copyright()` to populate meta tags, headers, and footers.
```html
= $site->title()->html() ?>
Hello world!
```
--------------------------------
### API GET Request with Basic Auth
Source: https://getkirby.com/docs/reference/objects/http/remote/request
Example of making a GET request to an API endpoint with HTTP Basic Authentication. Requires Basic auth to be enabled in Kirby's config.
```php
'GET',
'headers' => [
'Authorization: Basic ' . base64_encode($email . ':' . $password)
],
]);
if ($response->code() === 200) {
$data = json_decode($response->content())->data;
dump($data);
}
```
--------------------------------
### Create New Project with Starterkit via Composer
Source: https://getkirby.com/docs/guide/quickstart
Use Composer to create a new project based on the Kirby Starterkit. Replace 'project-folder' with your desired directory name.
```bash
composer create-project getkirby/starterkit project-folder
```
--------------------------------
### Instantiate Darkroom
Source: https://getkirby.com/docs/reference/objects/image/darkroom
Create a new instance of the Darkroom class. This is the starting point for image manipulation.
```php
new Darkroom()
```
--------------------------------
### Example: Get the Params object
Source: https://getkirby.com/docs/reference/objects/http/request
Illustrates how to obtain the `Params` object, which contains all URL parameters.
```APIDOC
## Get the Params object
### Description
The `$params` object aggregates all URL parameters passed to the request.
### Method
```php
$request->params();
```
### Example
```php
$params = $request->params();
```
```
--------------------------------
### Initialize DDEV Project
Source: https://getkirby.com/docs/cookbook/development-deployment/ddev
Navigate to your project directory and run this command to initialize a DDEV project. Ensure DDEV is installed and Docker is running.
```bash
ddev config
```
--------------------------------
### Get Website Document Root
Source: https://getkirby.com/docs/reference/system/roots/index
Use this to retrieve the document root of the website. No setup is required.
```php
= $kirby->root('index') ?>
```
--------------------------------
### Get the start index of the current page
Source: https://getkirby.com/docs/reference/objects/cms/pagination/start
Use the start() method on a Pagination object to retrieve the index of the first item displayed on the current page. This method modifies the existing Pagination object and returns it.
```php
$pagination->start(): int
```
--------------------------------
### Instantiate AudioFilePreview
Source: https://getkirby.com/docs/reference/objects/panel-ui-filepreviews/audio-file-preview/__construct
Use this constructor to create a new AudioFilePreview instance. The $file parameter is required, and $component defaults to 'k-audio-file-preview'. This class is marked as unstable.
```php
new AudioFilePreview(Kirby\Cms\File $file, string $component = 'k-audio-file-preview')
```
--------------------------------
### Get a Slice of a Kirby Collection
Source: https://getkirby.com/docs/reference/objects/toolkit/collection/slice
Use the slice method to get a portion of a collection. Specify the starting offset and an optional limit for the number of items. This method returns a new collection and does not alter the original.
```php
$collection->slice(int $offset = 0, int|null $limit = null): Kirby\Toolkit\Collection
```
--------------------------------
### Setup Section
Source: https://getkirby.com/docs/reference/objects/cms/section
Static method used for the initial setup of a section. This is typically called internally by Kirby.
```php
Section::setup()
```
--------------------------------
### Dockerfile for Kirby Starterkit with Bind Mount
Source: https://getkirby.com/docs/cookbook/development-deployment/kirby-meets-docker
This Dockerfile sets up an Ubuntu environment with Apache and PHP, configured for Kirby. It includes timezone settings, package installations, Apache configuration, and user ID modification for local file access.
```dockerfile
# Use latest offical ubuntu image
FROM ubuntu:latest
# Set timezone
ENV TZ=Europe/Berlin
# Set geographic area using above variable
# This is necessary, otherwise building the image doesn't work
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# Remove annoying messages during package installation
ARG DEBIAN_FRONTEND=noninteractive
# Install packages: web server & PHP plus extensions
RUN apt-get update && apt-get install -y \
apache2 \
apache2-utils \
ca-certificates \
php \
libapache2-mod-php \
php-curl \
php-dom \
php-gd \
php-intl \
php-json \
php-mbstring \
php-xml \
php-zip && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Copy virtual host configuration from current path onto existing 000-default.conf
COPY default.conf /etc/apache2/sites-available/000-default.conf
# Remove default content (existing index.html)
RUN rm /var/www/html/*
# Activate Apache modules headers & rewrite
RUN a2enmod headers rewrite
# Change web server's user id to match local user, replace with your local user id
RUN usermod --uid 1001 www-data
# Tell container to listen to port 80 at runtime
EXPOSE 80
```
--------------------------------
### Get a slice of Blocks object
Source: https://getkirby.com/docs/reference/objects/cms/blocks/slice
Use the slice() method to get a subset of blocks. Specify the starting offset and the number of elements to retrieve. This method returns a new object without altering the original.
```php
$blocks->slice(int $offset = 0, int|null $limit = null): Kirby\Cms\Blocks
```
--------------------------------
### Initialize OptionsApi
Source: https://getkirby.com/docs/reference/objects/option/options-api
Instantiate the OptionsApi class to begin fetching options.
```php
new OptionsApi()
```
--------------------------------
### Get LockedContentException Relative File Path
Source: https://getkirby.com/docs/reference/objects/content/locked-content-exception
Retrieve the file path of the LockedContentException relative to the Kirby installation.
```php
$lockedContentException->getFileRelative()
```
--------------------------------
### Dockerfile for Ubuntu with Apache and PHP
Source: https://getkirby.com/docs/cookbook/development-deployment/kirby-meets-docker
This Dockerfile sets up an Ubuntu environment, installs Apache, PHP, and required extensions, clones the Kirby Starterkit, configures Apache, and exposes port 80. Use this to build a custom image for your web application.
```dockerfile
# Use latest offical ubuntu image
FROM ubuntu:latest
# Set timezone environment variable
ENV TZ=Europe/Berlin
# Set geographic area using above variable
# This is necessary, otherwise building the image doesn't work
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# Remove annoying messages during package installation
ARG DEBIAN_FRONTEND=noninteractive
# Install packages: web server Apache, PHP and extensions
RUN apt-get update && apt-get install --no-install-recommends -y \
apache2 \
apache2-utils \
ca-certificates \
git \
php \
libapache2-mod-php \
php-curl \
php-dom \
php-gd \
php-intl \
php-json \
php-mbstring \
php-xml \
php-zip && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Copy virtual host configuration from current path onto existing 000-default.conf
COPY default.conf /etc/apache2/sites-available/000-default.conf
# Remove default content (existing index.html)
RUN rm /var/www/html/*
# Clone the Kirby Starterkit
RUN git clone --depth 1 https://github.com/getkirby/starterkit.git /var/www/html
# Fix files and directories ownership
RUN chown -R www-data:www-data /var/www/html/
# Activate Apache modules headers & rewrite
RUN a2enmod headers rewrite
# Tell container to listen to port 80 at runtime
EXPOSE 80
# Start Apache web server
CMD [ "/usr/sbin/apache2ctl", "-DFOREGROUND" ]
```
--------------------------------
### Clone Kirby Starterkit with Git
Source: https://getkirby.com/docs/cookbook/development-deployment/kirby-meets-docker
Clone the Kirby Starterkit repository into a local directory using Git. This is the first step for setting up a local Starterkit.
```bash
cd docker-example-3
git clone https://github.com/getkirby/starterkit.git
```
--------------------------------
### Basic video embed
Source: https://getkirby.com/docs/reference/templates/helpers/video
Use this basic example to embed a YouTube video. No additional setup is required.
```php
= video('https://www.youtube.com/watch?v=QwjX8JAwBws') ?>
```
--------------------------------
### Get Roles Folder Root
Source: https://getkirby.com/docs/reference/system/roots/roles
Use this to retrieve the absolute path to the roles folder. No setup is required.
```php
= $kirby->root('roles') ?>
```
--------------------------------
### Initialize FileCache with Options
Source: https://getkirby.com/docs/reference/objects/cache/file-cache/__construct
Instantiate the FileCache with an array of options. The 'root' option is required. Other options include 'prefix' and 'extension' for customizing cache file behavior.
```php
new FileCache(array $options)
```
--------------------------------
### Create a new file with $site->createFile()
Source: https://getkirby.com/docs/reference/objects/cms/site/create-file
Use this method to create a new file, specifying its filename, parent, source path, template, and content. Ensure the source file exists at the provided path. The impersonate method is used here for demonstration purposes.
```php
$kirby->impersonate('kirby');
$newPage = $site->createFile(
[
'filename' => 'trees.jpg',
'parent' => $site,
'source' => $kirby->root('assets') . '/images/trees.jpg',
'template' => 'image',
'content' => [
'alt' => 'A beautiful flower',
],
]
);
```
--------------------------------
### Get Kirby Media Root
Source: https://getkirby.com/docs/reference/system/roots/media
Use this to retrieve the absolute path to the media folder. No setup is required.
```php
= $kirby->root('media') ?>
```
--------------------------------
### Database::instance()
Source: https://getkirby.com/docs/reference/objects/database/database/instance
Retrieves a started instance of the Kirby Database. You can optionally specify an ID to get a specific instance.
```APIDOC
## Database::instance()
### Description
Returns one of the started instances of the Kirby Database. If no ID is provided, it returns the default instance.
### Method
`static`
### Endpoint
N/A (This is a static method call within the Kirby framework)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```php
// Get the default database instance
$db = Kirby\Database\Database::instance();
// Get a specific database instance by ID
$specificDb = Kirby\Database\Database::instance('my_custom_db');
```
### Response
#### Success Response (200)
- **Kirby\Database\Database|null**: The requested database instance or null if not found.
#### Response Example
```json
{
"instance": "Kirby\\Database\\Database"
}
```
### Error Handling
- Returns `null` if the specified instance ID does not exist.
```
--------------------------------
### Get LayoutColumns from Offset
Source: https://getkirby.com/docs/reference/objects/cms/layout-columns/offset
Returns a new LayoutColumns object starting from the specified offset. The original object is not modified.
```php
$layoutColumns->offset(int $offset): Kirby\Cms\LayoutColumns
```
--------------------------------
### Example Usage of thumb() Method
Source: https://getkirby.com/docs/guide/read-me
Demonstrates how to use the `thumb()` method with different options for resizing and cropping images. The method can accept null, a string referring to a preset, or an array of options.
```php
// Example 1: Using a preset from config
$image->thumb('preview');
// Example 2: Using an array of options
$image->thumb([
'width' => 800,
'height' => 600,
'crop' => true
]);
// Example 3: Using default preset from config (no parameter)
$image->thumb();
```
--------------------------------
### Languages Offset Method
Source: https://getkirby.com/docs/reference/objects/cms/languages/offset
The offset() method allows you to get a new Languages object starting from a specific index.
```APIDOC
## Languages Offset Method
### Description
Returns a new object starting from the given offset.
### Method
```php
$languages->offset(int $offset): Kirby\Cms\Languages
```
### Parameters
#### Path Parameters
- **offset** (int) - Required - The index to start from
### Response
#### Success Response (200)
- **Kirby\Cms\Languages** - A new Languages object starting from the specified offset.
### Notes
This method does not modify the existing `$languages` object but returns a new object with the changes applied.
```
--------------------------------
### Get Assets Folder URL
Source: https://getkirby.com/docs/reference/system/urls/assets
Use this method to retrieve the URL of the assets folder. No specific setup is required.
```php
= $kirby->url('assets') ?>
```
--------------------------------
### Instantiate AudioFilePreview
Source: https://getkirby.com/docs/reference/objects/panel-ui-filepreviews/audio-file-preview
Use the constructor to create a new instance of the AudioFilePreview class. This class is marked as unstable.
```php
new AudioFilePreview()
```
--------------------------------
### Blog Template Header and Section Setup
Source: https://getkirby.com/docs/cookbook/content-structure/create-a-blog
Includes header and menu snippets and sets up the main content section with a 'blog' class for styling.
```php
```
--------------------------------
### Instantiate PagesCollector
Source: https://getkirby.com/docs/reference/objects/panel-collector/pages-collector
Create a new instance of the PagesCollector. No specific setup is required beyond having Kirby Panel installed.
```php
new PagesCollector()
```
--------------------------------
### Instantiate VideoFilePreview
Source: https://getkirby.com/docs/reference/objects/panel-ui-filepreviews/video-file-preview
Creates a new instance of the VideoFilePreview class. This is a basic setup for using the preview functionality.
```php
new VideoFilePreview()
```
--------------------------------
### Instantiate FilesCollector
Source: https://getkirby.com/docs/reference/objects/panel-collector/files-collector
Create a new instance of the FilesCollector class. No specific setup is required beyond having Kirby installed.
```php
new FilesCollector()
```
--------------------------------
### Get a slice of a Path object
Source: https://getkirby.com/docs/reference/objects/http/path/slice
Use $path->slice() to get a new Path object representing a portion of the original. Specify the starting offset and an optional limit for the number of elements. The original object remains unchanged.
```php
$path->slice(int $offset = 0, int|null $limit = null): Kirby\Http\Path
```
--------------------------------
### Create a new directory
Source: https://getkirby.com/docs/reference/objects/aliases/dir
Example of how to create a new directory using Dir::make().
```APIDOC
## POST /websites/getkirby/Dir::make
### Description
Creates a new directory at the specified path.
### Method
POST
### Endpoint
`/websites/getkirby/Dir::make`
### Parameters
#### Query Parameters
- **path** (string) - Required - The absolute path where the directory should be created.
### Request Example
```json
{
"path": "$kirby->root('index') . '/test'"
}
```
### Response
#### Success Response (200)
- **success** (boolean) - Indicates if the directory creation was successful.
#### Response Example
```json
{
"success": true
}
```
```
--------------------------------
### Get a slice of a structure object
Source: https://getkirby.com/docs/reference/objects/cms/structure/slice
Use the slice method to get a subset of structure elements. Specify the starting offset and the number of elements to retrieve. This method returns a new Structure object without modifying the original.
```php
$structure->slice(int $offset = 0, int|null $limit = null): Kirby\Cms\Structure
```
--------------------------------
### Get Current Version
Source: https://getkirby.com/docs/reference/objects/cms-system/update-status/current-version
Returns the currently installed version of the system. This method modifies the existing $updatestatus object and returns it.
```php
$updateStatus->currentVersion(): string|null
```
--------------------------------
### User Object Examples
Source: https://getkirby.com/docs/reference/objects/aliases/user
Provides practical examples of using the User object's methods, such as checking administrative privileges, converting the object to an array, changing the user's name, and fetching associated files.
```APIDOC
## User Object Examples
### Check if the user is an admin
```php
if ($user->isAdmin()) {
echo "Hey, great, you can do anything you like!";
}
```
### Convert user object to array
```php
$userData = $user->toArray();
```
### Change the user name programmatically
```php
$user->changeName('new-name');
```
### Fetch all files belonging to the user object
```php
$userFiles = $user->files();
```
**Note:** In production code, always check if the User object exists before calling its methods.
```
--------------------------------
### Get All Blueprints
Source: https://getkirby.com/docs/reference/objects/cms/app/blueprints
Retrieves all available blueprints for the current Kirby installation. You can optionally specify a type of blueprint to filter the results.
```APIDOC
## GET /blueprints
### Description
Returns all available blueprints for this installation.
### Method
GET
### Endpoint
/blueprints
### Parameters
#### Query Parameters
- **type** (string) - Optional - Specifies the type of blueprints to retrieve (e.g., 'pages'). Defaults to 'pages'.
### Response
#### Success Response (200)
- **blueprints** (array) - An array containing blueprint definitions.
### Response Example
```json
{
"blueprints": [
{
"name": "default",
"title": "Default Page",
"icon": "page",
"fields": {
"title": {
"label": "Title",
"type": "text"
}
}
}
]
}
```
```
--------------------------------
### Electron Main Process Configuration
Source: https://getkirby.com/docs/cookbook/headless/headless-kiosk-application
Sets up the main Electron window, including loading the application and handling window events. Configure autoplay policies and window properties as needed.
```javascript
const path = require("path");
const { app, BrowserWindow } = require("electron");
const serve = require("electron-serve");
const loadURL = serve({ directory: "public" });
app.commandLine.appendSwitch("autoplay-policy", "no-user-gesture-required");
let mainWindow;
function createWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 1920,
height: 1080,
webPreferences: {
nodeIntegration: true,
webSecurity: false,
},
icon: path.join(__dirname, "icons/output/icons/favicon.png"),
show: false,
autoHideMenuBar: true,
});
loadURL(mainWindow);
mainWindow.on("closed", function () {
mainWindow = null;
});
mainWindow.once("ready-to-show", () => {
mainWindow.show();
});
}
app.on("ready", createWindow);
app.on("window-all-closed", function () {
if (process.platform !== "darwin") app.quit();
});
app.on("activate", function () {
if (mainWindow === null) createWindow();
});
```
--------------------------------
### Site Content Example
Source: https://getkirby.com/docs/guide/templates/collections---Examples%3A%60%60%60php%3C?php%24customCollection+=+collection%28%27projects%27%29%3Bdump%28%24customCollection%29%3B%60%60%60
An example of the content structure for `/content/site.txt`, demonstrating fields like Title, Author, Description, and Copyright.
```text
Title: Kirby Starterkit
----
Author: Content Folder GmbH & Co. KG
----
Description: This is Kirby's Starterkit.
----
Copyright: © 2009–2026 The Kirby Team
```
--------------------------------
### Example: Get a specific variable from the query string
Source: https://getkirby.com/docs/reference/objects/http/request
Demonstrates how to retrieve a specific query parameter using the `query()` method.
```APIDOC
## Get a specific variable from the query string
### Description
This example shows how to access a query parameter named 'filter'.
### Method
```php
$request->query()->filter();
```
### Example
```php
$filter = $request->query()->filter();
```
```
--------------------------------
### Get Media Folder URL in Kirby
Source: https://getkirby.com/docs/reference/system/urls/media
Use this snippet to output the URL of the media folder. No special setup is required.
```php
= $kirby->url('media') ?>
```
--------------------------------
### Site Constructor
Source: https://getkirby.com/docs/reference/objects/panel/site/__construct
Documentation for the `new Site()` constructor.
```APIDOC
## new Site()
### Description
Initializes a new Site object.
### Method
Constructor
### Parameters
#### Path Parameters
- **$model** (Kirby\Cms\ModelWithContent) - Required - The model associated with the site.
### Parent class
`Kirby\Panel\Site` inherited from `Kirby\Panel\Model`
```
--------------------------------
### Run Docker Container with Volume Mount
Source: https://getkirby.com/docs/cookbook/development-deployment/kirby-meets-docker
Start a Docker container in detached mode, mapping port 80, naming it 'mycontainer', and mounting the local 'starterkit' directory to '/var/www/html' inside the container. This ensures that changes to your local files are reflected in the container and vice versa.
```bash
docker run -d --name mycontainer -p 80:80 \
--mount type=bind,source=$(pwd)/starterkit,destination=/var/www/html \
docker-starterkit
```
--------------------------------
### Get Default Collections Root
Source: https://getkirby.com/docs/reference/system/roots/collections
Use this to retrieve the default directory path where shared collections are stored. No setup required.
```php
= $kirby->root('collections') ?>
```
--------------------------------
### Get Blueprints Root
Source: https://getkirby.com/docs/reference/system/roots/blueprints
Use this to retrieve the absolute path to the blueprints folder. No setup is required if using the default configuration.
```php
= $kirby->root('blueprints') ?>
```
--------------------------------
### Custom URL Setup
Source: https://getkirby.com/docs/reference/system/urls/media
Demonstrates how to overwrite default URLs by providing a custom setup in the Kirby constructor.
```APIDOC
## Custom URL Setup in index.php
### Description
If you want to overwrite the URL, you can do this in your `index.php` by passing a custom URL setup to the Kirby constructor.
### Method
POST (Implicitly via Kirby constructor)
### Endpoint
`index.php` (Kirby Constructor)
### Parameters
#### Request Body
- **urls** (array) - Required - An associative array where keys are URL identifiers and values are the custom URLs.
- **if-you-want-to-overwrite-the-url-you-can-do-this-in-your-index-php-by-passing-a-custom-url-setup-to-the-kirby-constructor-php-in** (string) - Example custom URL.
### Request Example
```php
[
'if-you-want-to-overwrite-the-url-you-can-do-this-in-your-index-php-by-passing-a-custom-url-setup-to-the-kirby-constructor-php-in' => 'https://example.com/custom/url',
],
]);
echo $kirby->render();
?>
```
### Response
#### Success Response (200)
- **rendered_page** (string) - The rendered HTML of the Kirby page.
```
--------------------------------
### Get Site Base URL
Source: https://getkirby.com/docs/reference/objects/cms/site/url
Use this snippet to fetch the main URL of your Kirby site. No special setup is required.
```php
= $site->url() ?>
```
--------------------------------
### Instantiate Item Class
Source: https://getkirby.com/docs/reference/objects/cms/item
Demonstrates how to create a new instance of the Item class. No specific setup is required beyond having Kirby's core classes available.
```php
new Item()
```
--------------------------------
### Example PHP Array of Options
Source: https://getkirby.com/docs/reference/panel/fields/select
Illustrates the resulting PHP array of options after applying advanced text and value formatting to API-fetched data.
```php
[
value: 'APPLE',
text: 'Apple - Products: 3'
],
[
value: 'INTEL',
text: 'Intel - Products: 1'
],
[
value: 'MICROSOFT',
text: 'Microsoft - Products: 3'
]
```
--------------------------------
### Get Authentication Status
Source: https://getkirby.com/docs/reference/objects/cms/app-users
Check the authentication status of the current user. No specific setup is required if the AppUsers object is available.
```php
$appUsers->auth()
```
--------------------------------
### Instantiate Darkroom Class
Source: https://getkirby.com/docs/reference/objects/image/darkroom/__construct
Use this constructor to create a new instance of the Darkroom class. It accepts an optional array of settings to configure its behavior.
```php
new Darkroom(array $settings = [ ])
```
--------------------------------
### Get all Kirby roots
Source: https://getkirby.com/docs/reference/system/roots
Retrieve the `$roots` object to access all installation folder roots. This object contains methods for each root directory.
```php
$roots = $kirby->roots();
```