예제 #1
0
<?php

use FB;
use My\Helper;
$app->get('/api-v1.0/article/list/', function () use($app) {
    $articles = ArticleModel::listArticles();
    if (!is_array($articles)) {
        return Helper::response(false, array(), 'Application error', 500);
    }
    return Helper::response(true, $articles);
});
$app->get('/api-v1.0/article/get/:id/', function ($id) use($app) {
    $article = ArticleModel::getArticle($id);
    if (empty($article)) {
        return Helper::response(false, array(), 'Article not found', 404);
    }
    return Helper::response(true, $article);
});
$app->post('/api-v1.0/article/add/', function () use($app) {
    if (!($account = Helper::checkSecret())) {
        return;
    }
    $artId = ArticleModel::addArticle(array('acc_id' => $account['acc_id'], 'art_title' => $app->request->post('art_title', ''), 'art_body' => $app->request->post('art_body', '')));
    if (empty($artId)) {
        return Helper::response(false, array(), 'Application error', 500);
    }
    return Helper::response(true, array('art_id' => $artId));
});
$app->post('/api-v1.0/article/patch/', function () use($app) {
    if (!($account = Helper::checkSecret())) {
        return;