Exemplo n.º 1
0
$app->get('/authors/all/:limit', function ($limit) use($app) {
    $db = connect();
    $authors = $db->libavtors()->select("aid, FirstName, middlename, LastName")->limit($limit);
    $app->response()->header('Content-Type', 'application/json', 'charset=utf8');
    echo json_encode($authors, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
});
$app->get('/authors/:q/:search(/:limit)', function ($q, $search, $limit = 10) use($app) {
    $db = connect();
    $authors = $db->authors()->select("aid, FullName")->where("{$q} LIKE ?", "%{$search}%")->limit($limit);
    $app->response()->header('Content-Type', 'application/json', 'charset=utf8');
    echo json_encode($authors, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
});
$app->get('/books/:limit', function ($limit) {
    $connection = new PDO("mysql:dbname=library;host=127.0.0.1;charset=utf8", "library_admin", "123456");
    $db = new NotORM($connection);
    $books = $db->libbook()->select("bid, Title, Title1")->limit($limit);
    foreach ($books as $id => $book) {
        echo "{$book['Title']} {$book['Title1']}<br>";
    }
});
$app->get('/books/by/:aid(/:lang)(/:deleted)', function ($aid, $lang = NULL, $deleted = NULL) use($app) {
    $connection = new PDO("mysql:dbname=library;host=127.0.0.1;charset=utf8", "library_admin", "123456");
    $db = new NotORM($connection);
    $booksBySeries = [];
    $books = $db->BooksByAuthor()->where("aid = ?", $aid);
    if ($deleted) {
        $books = $books->where("Deleted <> ?", 1);
    }
    if ($lang) {
        $books = $books->where("lang = ?", $lang);
    }