PHP code example of getkirby / database-storage

1. Go to this page and download the library: Download getkirby/database-storage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

getkirby / database-storage example snippets




use Kirby\Database\Database;

return [
    'database' => [
        'comments' => new Database([
            'type'     => 'sqlite',
            'database' => dirname(__DIR__) . '/db/comments.sqlite'
        ])
    ]
];



use Kirby\Cms\Page;
use Kirby\DatabaseStorage\HasDatabaseChildren;

class CommentsPage extends Page
{
    use HasDatabaseChildren;

    public const DATABASE_CHILD_MODEL = CommentPage::class;
}



use Kirby\DatabaseStorage\DatabasePage;

class CommentPage extends DatabasePage
{
    public const DATABASE_NAME = 'comments';
    public const DATABASE_TABLE = 'comments';
    public const DATABASE_FIELDS = [
        'text',
        'email',
    ];
}