:::

10. NewsRest.php

<?php
require_once "SimpleRest.php";
require_once "header.php";

class NewsRest extends SimpleRest
{
    public function __construct()
    {
    }

    // 取得所有文章的 json
    public function index($p = 1, $cate_id = 0, $keyword = '', $year = '')
    {
        $data = index($p, $cate_id, $keyword, $year);
        return $this->encodeJson($data);
    }

    // 取得單一文章的 json
    public function show($id)
    {
        $data = show($id);
        return $this->encodeJson($data);
    }

    // 取得年度文章數
    public function count()
    {
        $data = article_count();
        return $this->encodeJson($data);
    }

    public function encodeJson($responseData)
    {
        if (empty($responseData)) {
            $statusCode   = 404;
            $responseData = array('error' => '無資料');
        } else {
            $statusCode = 200;
        }
        $this->setHttpHeaders($statusCode);

        $jsonResponse = json_encode($responseData, 256);
        return $jsonResponse;
    }

}

 


:::

書籍目錄

展開 | 闔起

http%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbsn%3D53%26tbdsn%3D1877

計數器

今天: 1928192819281928
昨天: 2395239523952395
總計: 7917873791787379178737917873791787379178737917873