-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcms_with_pagination.php
61 lines (44 loc) · 1.3 KB
/
cms_with_pagination.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
require_once 'assets/config/config.php';
require_once "vendor/autoload.php";
use PhotoTech\CMS;
use PhotoTech\Pagination;
/*
* The below must be used in order for the json to be decoded properly.
*/
try {
$data = json_decode(file_get_contents('php://input'), true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
}
$total_count = CMS::countAllPage('blog'); // Total Records in the db table:
/* Send the 3 variables to the Pagination class to be processed */
$pagination = new Pagination($data['current_page'], $data['per_page'], $total_count);
/* Grab the offset (page) location from using the offset method */
$offset = $pagination->offset();
/*
* Grab the data from the CMS class method *static*
* and put the data into an array variable.
*/
$cms = CMS::page($data['per_page'], $offset, 'blog');
output($cms);
/*
* Throw error if something is wrong
*/
function errorOutput($output, $code = 500) {
http_response_code($code);
try {
echo json_encode($output, JSON_THROW_ON_ERROR);
} catch (JsonException) {
}
}
/*
* After converting data array to JSON send back to javascript using
* this function.
*/
function output($output) {
http_response_code(200);
try {
echo json_encode($output, JSON_THROW_ON_ERROR);
} catch (JsonException) {
}
}