:::

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;
    }

}

 


:::

書籍目錄

展開 | 闔起

快速登入


https%3A%2F%2Fcampus-xoops.tn.edu.tw%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1877%26tbsn%3D53

計數器

今天: 6470647064706470
昨天: 2489248924892489
總計: 8028452802845280284528028452802845280284528028452