forked from Greg0/XML-FileDatabase
/
example.php
38 lines (35 loc) · 1016 Bytes
/
example.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
<?php
define('DB_PATH', __DIR__.'/db/');
require_once 'xmlDB.php';
if (isset($_POST['add']))
{
unset($_POST['add']);
$news = Database::factory('news');
foreach ($_POST as $field => $value)
{
$news->{$field} = $value;
}
$news->save();
}
$count = Database::factory('news')->select()->count();
?>
<form action="" method="post">
<label>Title:</label>
<input type="text" name="title" /><br />
<label>Author:</label>
<input type="text" name="author" /><br />
<label>Content:</label>
<textarea name="content"></textarea><br />
<input type="submit" name="add" />
</form>
<h1>Newest informations, you have <?php echo $count; ?> news</h1>
<hr />
<?php
$news = Database::factory('news')->select()->order_by('id', 'DESC')->find_all();
foreach($news as $post):
?>
<h2><?php echo $post->title; ?></h2>
<small><?php echo $post->author; ?></small>
<p><?php echo $post->content; ?></p>
<hr />
<?php endforeach; ?>