<?php require_once 'init.php'; $app->get("/authors(/:id)", function ($id = null) use($app, $db) { $response = array(); $app->response()->header('Content-type', 'application/json'); $authors = $db->users(); if ($id == null) { $response = decode_NotORM($authors); } else { $author = $authors->where('id', $id)->fetch(); foreach ($author as $key => $value) { $response[$key] = $value; } } echo json_encode($response); }); $app->run();
$blogs_config = json_decode(file_get_contents('blog-config.json')); $blogs = $db->blogs()->where('id', $blogs_config->trending); $response = decode_NotORM($blogs); echo json_encode($response); }); $app->get("/search", function () use($app, $db) { $response = array(); $app->response()->header('Content-type', 'application/json'); $blogs = $db->blogs(); if (isset($_GET) and !empty($_GET)) { // search for title if (isset($_GET['title']) and !empty($_GET['title'])) { $title = $_GET['title']; $blogs->where(array("title LIKE ?" => '%' . $title . '%')); } // set offset if necessary $offset = null; if (isset($_GET['offset'])) { $offset = $_GET['offset']; } // set limit if given if (isset($_GET['limit'])) { $limit = $_GET['limit']; $blogs->limit($limit, $offset); } $blogs->fetch(); $response = decode_NotORM($blogs); } echo json_encode($response); }); $app->run();
<?php # @params : id = user_id $response = array(); $app->response()->header('Content-type', 'application/json'); $users = $db->users(); if ($id == null) { $response = decode_NotORM($users); } else { $user = $users->where('id', $id)->fetch(); foreach ($user as $key => $value) { if ($key === "password") { continue; } $response[$key] = $value; } } echo json_encode($response);