예제 #1
0
파일: index.php 프로젝트: justim/vice
<?php

require 'Db.php';
require '../Vice.php';
$sqlite = new PDO('sqlite:' . __DIR__ . '/database.sq3');
// table structure
// $sqlite->query("CREATE TABLE `users` (
//   `id` INTEGER PRIMARY KEY AUTOINCREMENT,
//   `name` varchar(50) DEFAULT NULL,
//   `emailaddress` varchar(100) DEFAULT NULL
// )");
$db = db($sqlite);
$app = new Vice('/', $db() + ['render' => include 'helpers/render.php']);
$app->registerFilter('is:logged', function ($server) {
    //TODO do some login foo
    return 'Yoda';
});
// mount an ajax app on the route /ajax
$app->route('ajax', 'is:logged is:ajax', include 'app/ajax.php');
$app->get('/', 'is:logged', function ($render, $isLogged) {
    echo $render('index.php', ['current_user_name' => $isLogged]);
});
$app->run();
예제 #2
0
파일: ajax.php 프로젝트: justim/vice
<?php

$ajax = new Vice();
// list all users
$ajax->get('users', function ($json, $users) {
    $json($users());
});
// get the information about one user
$ajax->get('users/<id>', function ($json, $users, $id) {
    $json($users($id));
});
// delete an user
$ajax->delete('users/<id>', function ($json, $id, $users, $post) {
    $users('delete', $id);
    $json(1);
});
// edit an user
$ajax->put('users/<id>', function ($json, $id, $users, $post) {
    $users($id, $post());
    $json(1);
});
// create an user
$ajax->put('users', function ($json, $users, $post) {
    $users($post());
    $json(1);
});
return $ajax;