lepisi-pengumuman/App/Controllers/Api.php

34 lines
691 B
PHP

<?php
namespace App\Controllers;
use App\Models\Post;
class Api
{
private $model;
public function __construct() {
$this->model = new Post();
}
public function posts() {
$get = [];
$get['count'] = 0;
$get['data'] = $this->model->showJoin();
if (array_key_exists(0, $get['data']) == false) {
$temp_data = $get['data'];
unset($get['data']);
$get['data'][] = $temp_data;
$temp_data = [];
}
if ($get['data'] != false) {
$get['count'] = count($get['data']);
}
header('Content-Type: application/json');
echo json_encode($get);
}
}