Skip to content

Commit 6311d1c

Browse files
committed
Update README.md
Signed-off-by: Aditya <aditaykumar2012@gmail.com>
1 parent 4256957 commit 6311d1c

19 files changed

+481
-0
lines changed

.idea/.gitignore

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/PHP-CURD-REST-API.iml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deployment.xml

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/category/create.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
header('Access-Control-Allow-Origin: *');
3+
header('Content-Type: application/json');
4+
header('Access-Control-Allow-Methods: POST');
5+
header('Access-Control-Allow-Headers: Access-Control-Allow-Headers, Content-Type: Access-Control-Allow-Methods, Authorization, X-Requested-With');
6+
include_once '../../config/Database.php';
7+
include_once '../../models/Category.php';
8+
$database = new Database();
9+
$db = $database->connect();
10+
$cat = new Category($db);
11+
$data = json_decode(file_get_contents("php://input"));
12+
$cat->name = @$data->name;
13+
14+
$return = $cat->name ? $cat->create() ? array('status' => true, 'message' => 'Category Created Successfully...') : array('status' => false, 'message' => 'Category Not Created') : array('status' => false, 'message' => 'Category Name Is Empty');
15+
echo json_encode($return);

api/category/delete.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
header('Access-Control-Allow-Origin: *');
3+
header('Content-Type: application/json');
4+
header('Access-Control-Allow-Methods: DELETE');
5+
header('Access-Control-Allow-Headers: Access-Control-Allow-Headers, Content-Type
6+
Access-Control-Allow-Methods, Authorization, X-Requested-With');
7+
include_once '../../config/Database.php';
8+
include_once '../../models/Category.php';
9+
$database = new Database();
10+
$db = $database->connect();
11+
$cat = new Category($db);
12+
$data = json_decode(file_get_contents("php://input"));
13+
$cat->id = $data->id;
14+
$return = $cat->delete() ? array('status' => true, 'message' => 'Category Deleted Successfully...') : array('status' => false, 'message' => 'Category Not Deleted');
15+
echo json_encode($return);

api/category/read.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
header('Access-Control-Allow-Origin: *');
3+
header('Content-Type: application/json');
4+
include_once '../../config/Database.php';
5+
include_once '../../models/Category.php';
6+
$database = new Database();
7+
$db = $database->connect();
8+
$category = new Category($db);
9+
$result = $category->read();
10+
$num = $result->rowCount();
11+
if ($num > 0) {
12+
$cat_arr = array();
13+
$cat_arr['data'] = array();
14+
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
15+
$cat_item = array(
16+
'id' => $row['id'],
17+
'name' => $row['name'],
18+
);
19+
array_push($cat_arr['data'], $cat_item);
20+
}
21+
echo json_encode($cat_arr);
22+
} else {
23+
echo json_encode(
24+
array('message' => 'No Categories Found.')
25+
);
26+
}

api/category/read_single.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
header('Access-Control-Allow-Origin: *');
3+
header('Content-Type: application/json');
4+
include_once '../../config/Database.php';
5+
include_once '../../models/Category.php';
6+
$database = new Database();
7+
$db = $database->connect();
8+
$cat = new Category($db);
9+
$cat->id = isset($_GET['id']) ? $_GET['id'] : die('Request Failed');
10+
$cat->read_single();
11+
$cat_arr = array(
12+
'id' => $cat->id,
13+
'name' => $cat->name,
14+
);
15+
print_r(json_encode($cat_arr));
16+
die();

0 commit comments

Comments
 (0)