Created
January 18, 2016 01:00
-
-
Save vanilla-thunder/0f92ef15d28b1e1e0b34 to your computer and use it in GitHub Desktop.
using jamesmoss/Flywheel database with Flight php micro framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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