Skip to content

Instantly share code, notes, and snippets.

@vanilla-thunder
Created January 18, 2016 01:00
Show Gist options
  • Save vanilla-thunder/0f92ef15d28b1e1e0b34 to your computer and use it in GitHub Desktop.
Save vanilla-thunder/0f92ef15d28b1e1e0b34 to your computer and use it in GitHub Desktop.
using jamesmoss/Flywheel database with Flight php micro framework
<?php
/* loading flywheel and flight with composer
* $ composer require mikecao/flight
* $ composer require jamesmoss/flywheel
*/
require 'vendor/autoload.php';
// this is how regular flywheel configuration looks like:
// you can remove this rows later, they are just as example
$db = new \JamesMoss\Flywheel\Config('db');
$posts = new \JamesMoss\Flywheel\Repository('posts', $db);
// registering flywheel in flight:
Flight::register('posts','\JamesMoss\Flywheel\Repository',array('posts', new \JamesMoss\Flywheel\Config('db')));
Flight::route('/posts/', function()
{
$posts = Flight::posts()->query()->execute();
echo "<pre>";
foreach($posts as $post)
{
var_dump($post);
}
echo "</pre>";
});
Flight::route('/', function()
{
$post = new \JamesMoss\Flywheel\Document(array(
'title' => 'An introduction to Flywheel',
'dateAdded' => new \DateTime('2016-10-10'),
'body' => 'A lightweight, flat-file, document database for PHP...',
'wordCount' => 7,
));
$id = Flight::serien()->store($post);
echo $id;
});
Flight::start();
// first open / and refresh 2-3 times to create demo posts
// and then open /posts/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment