Download the PHP package getkirby/database-storage without Composer

On this page you can find all versions of the php package getkirby/database-storage. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package database-storage

Kirby Database Storage Plugin

Adds support for pages stored in a database.

[!IMPORTANT]
This plugin is still in an early alpha state. Use with caution.

database-storage

Features

This plugin already provides good support for pages from databases, but has still some limitations. Here is a list of supported page features:

File support

Files are stored in the content folder. A folder for each page is created as soon as files are uploaded. The UUID is used as folder name. File information is still stored in text files and not yet in the database.

[!WARNING]
This plugin requires UUIDs to be switched on

Installation

Download

Download and copy this repository to /site/plugins/database-storage.

Composer

Git submodule

How it works?

Setting up a database

For this example, we are creating a new SQLite database in /site/db and call it comments.sqlite. But you can place it everywhere you like and then later change the path in the config. (see below)

Required fields

Our database models require a couple core fields to work correctly:

Field name Type Config
id INTEGER primary key, autoincrement, not null, unique
title TEXT
slug TEXT not null
uuid TEXT not null
created TEXT not null, default: CURRENT_TIMESTAMP
modified TEXT not null, default: CURRENT_TIMESTAMP
version TEXT not null
language TEXT not null
parent TEXT
template TEXT
num INTEGER default: NULL
lock TEXT
draft INTEGER not null, default: 1

SQLite has a very limited set of column types. You might want to choose more appropriate types for MySQL or other databases.

Once all those columns are in place, you can add your own custom columns for custom fields. For our comments example, we will create a text and an email column.

Here's a full SQL query to create our comments database.

Create a table using the Kirby CLI

If you are using the Kirby CLI, you can create a new table via the table:create command:

You will be asked to specify the database connection, the table name and the list of custom fields.

You can also provide database connection and table name immediately via arguments:

myDatabase is referencing the config key for the database connection defined in your config (see below)

Database Connection

We need to define the connection to our database in the /site/config/config.php under the database key. The name for the connection can be defined by you, but needs to match later with the DATABASE_NAME constant in our page model (see below)

Parent page

First, create a regular Kirby page that serves as the parent for your database pages. For our comments example, we create a new content folder called /content/comments with a text file called comments.txt. This will connect the page to a new comments.php template and – more importantly – a new CommentsPage model. This model is the key to load our child pages from the database (see the setup below)

Models

For the new comments page, the model will use the HasDatabaseChildren trait from our plugin. This trait will replace the $page->children() method and load children from our database. All we need to do is to define the child model with the DATABASE_CHILD_MODEL constant.

/site/models/comments.php

/site/models/comment.php

Each child of the comments page will now use a new CommentPage model and that model needs to extend the DatabasePage class from the plugin to make everything work. This class will overwrite all the page action methods to create, update and delete pages in the database and no longer on disk.

The constants in the model finalize our setup. DATABASE_NAME refers to our config setting (database.comments), DATABASE_TABLE needs to match the table name in our database and the DATABASE_FIELDS array defines all custom fields that are stored in the table. The required core fields (see above) are not included here.

Blueprints

Once the models are set up correctly, you can define your blueprints and sections exactly like you would before:

/site/blueprints/pages/comments.yaml

/site/blueprints/pages/comment.yaml

What’s Kirby?


License

MIT

Credits


All versions of database-storage with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1.0
getkirby/cms Version ^5.0
getkirby/composer-installer Version ^1.2.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package getkirby/database-storage contains the following files

Loading the files please wait ...