-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from RobertGrubb/updates
[Fixes] Fix delete and get by id when does not exist
- Loading branch information
Showing
10 changed files
with
121 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{ | ||
"title": "An example", | ||
"id": "5ed559fc3669f", | ||
"createdAt": 1591040508, | ||
"updatedAt": 1591040508 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../../vendor/autoload.php'; | ||
require_once __DIR__ . '/../../src/FilerDB.php'; | ||
|
||
try { | ||
// Instantiate Database | ||
$filerdb = new FilerDB\Instance([ | ||
|
||
// Required | ||
'root' => __DIR__ . '/database', | ||
|
||
// Optional configurations | ||
'includeTimestamps' => true, | ||
|
||
// Specify database | ||
'database' => 'todo', | ||
|
||
// Configs | ||
'createRootIfNotExist' => true, | ||
'createDatabaseIfNotExist' => true, | ||
'createCollectionIfNotExist' => true | ||
]); | ||
|
||
return $filerdb; | ||
} catch (Exception $e) { | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
// Include a file that returns the filerdb instance. | ||
$filerdb = require __DIR__ . '/filerdb.php'; | ||
|
||
if (!$filerdb) die('FilerDB was unable to instantiate.'); | ||
|
||
// Current action | ||
$action = (isset($_GET['a']) ? $_GET['a'] : false); | ||
|
||
if ($action === 'submit') { | ||
$todo = (isset($_POST['todo']) ? $_POST['todo'] : false); | ||
|
||
if ($todo !== false) { | ||
$filerdb->collection('items')->insert([ | ||
'title' => $todo | ||
]); | ||
} | ||
|
||
header('Location: index.php'); | ||
exit; | ||
|
||
} elseif ($action === 'remove') { | ||
$id = (isset($_GET['id']) ? $_GET['id'] : false); | ||
|
||
if ($id !== false) { | ||
$filerdb->collection('items')->id($id)->delete(); | ||
} | ||
|
||
header('Location: index.php'); | ||
exit; | ||
} | ||
|
||
// Retrieve all todo items | ||
$items = $filerdb->collection('items')->all(); | ||
|
||
?> | ||
|
||
<h1>Todo Items</h1> | ||
|
||
<form action="index.php?a=submit" method="POST"> | ||
<input type="text" name="todo" /> | ||
<button type="submit">Add</button> | ||
</form> | ||
|
||
<ul> | ||
<?php foreach ($items as $item): ?> | ||
<li><?= $item->title; ?> <a href="index.php?a=remove&id=<?= $item->id; ?>">[X]</a></li> | ||
<?php endforeach; ?> | ||
</ul> |
4 changes: 2 additions & 2 deletions
4
example/backup.php → examples/usage/backup.php
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters