Skip to content

Commit 476b9e0

Browse files
Update index.php
1 parent 8a26388 commit 476b9e0

File tree

1 file changed

+8
-39
lines changed

1 file changed

+8
-39
lines changed

api/index.php

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131
use jsonDB\Validate;
3232
use jsonDB\dbException;
3333

34+
// Проверяем папки DB, если нет создаем
35+
if (!file_exists($_db)){mkdir($_db);}
36+
if (!file_exists($_db . 'core')){mkdir($_db . 'core');}
37+
3438
// Создаем ключ доступа
3539
if (!file_exists($_db . 'core/key_db.txt')){
36-
3740
$ajax_key = Key::createNewRandomKey();
3841
$key_db = $ajax_key->saveToAsciiSafeString();
3942
file_put_contents($_db . 'core/key_db.txt', $key_db);
40-
4143
}
4244

4345
// Конфигурация
@@ -82,54 +84,21 @@
8284
$param_key = (isset($param['key'])) ? Db::clean($param['key']) : null;
8385

8486
if ($param_key == $this->get('settings')['db']["key"]) {
85-
$resp["status"] = "OK";
87+
$resp["status"] = "200 OK";
8688
$resp["code"] = 200;
87-
$resp["message"] = 'db_json_api works! To work, you need a key.';
89+
$resp["message"] = "RESTfull API json DB works! works! To work, you need a key.";
8890
echo json_encode($resp, JSON_PRETTY_PRINT);
8991
} else {
90-
$resp["status"] = "OK";
92+
$resp["status"] = "200 OK";
9193
$resp["code"] = 200;
92-
$resp["message"] = 'db_json_api works!';
94+
$resp["message"] = "RESTfull API json DB works!";
9395
echo json_encode($resp, JSON_PRETTY_PRINT);
9496
}
9597

9698
return $response->withStatus(200)->withHeader('Content-Type','application/json');
9799

98100
});
99101

100-
$app->get('/test', function (Request $request, Response $response, array $args) {
101-
102-
/*
103-
$res->with('property');
104-
$res->with('product_view');
105-
*/
106-
107-
$res = jsonDb::table("product")->where("id", ">=", 61456)->orderBy('id')->limit(15)->findAll()->asArray();
108-
109-
/*
110-
foreach($res AS $key => $unit){
111-
if (isset($key) && isset($unit)) {
112-
$item[$key] = $unit;
113-
$items["item"] = $item;
114-
}
115-
}
116-
*/
117-
118-
$resp = array();
119-
$resp["headers"]["status"] = "200 OK";
120-
$resp["headers"]["code"] = 200;
121-
$resp["headers"]["message"] = 'Access is denied';
122-
123-
$resp["body"]["items"] = $res;
124-
125-
print_r($resp);
126-
127-
echo json_encode($resp, JSON_PRETTY_PRINT);
128-
129-
return $response->withStatus(200)->withHeader('Content-Type','application/json');
130-
131-
});
132-
133102
$app->get('/{table:[\w]+}[/{id:[0-9]+}]', function (Request $request, Response $response, array $args) {
134103

135104
$table_name = $request->getAttribute('table');

0 commit comments

Comments
 (0)