https://github.com/jongacnik/kirby2-datastore
Kirby flat-file json datastore for large-ish quantities of data
https://github.com/jongacnik/kirby2-datastore
Last synced: 12 months ago
JSON representation
Kirby flat-file json datastore for large-ish quantities of data
- Host: GitHub
- URL: https://github.com/jongacnik/kirby2-datastore
- Owner: jongacnik
- Created: 2017-08-21T00:20:08.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-13T23:16:27.000Z (almost 9 years ago)
- Last Synced: 2025-02-12T18:18:51.860Z (over 1 year ago)
- Language: PHP
- Size: 479 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Kirby Datastore
Provides Kirby with a flat-file json datastore for housing large-ish quantities of data, and a panel field for managing this data.
## Instance
```php
// Get datastore instance
$database = site()->datastore();
// Get/Create a collection
$people = $database->collection('people');
// Get entries as array
$people->find();
```
The datastore is implemented with [Jisly](https://github.com/r0mdau/jisly), so refer to those docs for all methods. Sorry for the French but the code examples are good!
## Field
The `datastore` field is an extension of the structure field. Instead of the entries being saved into a page text file as yaml, the entries are saved to the datastore.
```yaml
people:
label: People
type: datastore
fields:
name:
label: Name
type: text
age:
label: Age
type: number
```
To access entries from the template:
```php
site()->datastore('people')->find();
```
### Field Options
```yaml
people:
label: People
type: datastore
collection: persons
fields:
name:
label: Name
type: text
email:
label: Email
type: email
age:
label: Age
type: number
glasses:
label: Glasses
type: toggle
columns:
name: Name
email:
label: Email
class: emailcolumnclass
details:
label: Details
width: 20%
glasses:
label: Glasses
sort: false
order: desc
rows: 25
```
## Options
Defaults shown
```php
c::set('datastore.location', kirby()->roots()->content());
c::set('datastore.dbname', 'datastore');
c::set('datastore.method', 'datastore');
```
## Usage
```yaml
entries:
label: Entries
type: datastore
```
## Filter Data
A custom filter can be applied to the data before it is put out as a json response. This is perfect if you need to modify some of the data for presentation, change columns, etc.
Create a simple plugin `site/plugins/mydatafilters/mydatafilters.php`:
```php