-
Notifications
You must be signed in to change notification settings - Fork 12
/
admin.php
executable file
·95 lines (89 loc) · 2.2 KB
/
admin.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* Blog - Admin Controller
*
* This file contains the admin controller for the blog example.
*
* LICENSE
*
* This file is part of the Breeze Framework package and is subject to the new
* BSD license. For full copyright and license information, please see the
* LICENSE file that is distributed with this package.
*
* @package Breeze
* @subpackage Examples
* @author Jeff Welch <whatthejeff@gmail.com>
* @copyright 2010-2011 Jeff Welch <whatthejeff@gmail.com>
* @license https://github.com/whatthejeff/breeze/blob/master/LICENSE New BSD License
* @link http://breezephp.com/
*/
get('/admin', function(){
redirect('/admin/posts');
});
/**
* Pre-processor for loading posts
*/
any(';^/admin/posts/(?<id>\d+);', function($app, $params){
load($app, $params['id']);
pass();
});
/**
* View actions
*
* GET /admin/posts/
* GET /admin/posts/:id
*/
get('/admin/posts', function(){
display('admin/posts/index', array(
'posts'=>Doctrine_Core::getTable('Post')->findAll())
);
});
get(';^/admin/posts/(?<id>\d+)$;', function($app, $params) {
display('admin/posts/show');
});
/**
* New actions
*
* GET /admin/posts/new
* POST /admin/posts
*/
get('/admin/posts/new', function(){
display('admin/posts/new');
});
post('/admin/posts', function(){
if (save(new Post())) {
flash('notice', POST_CREATED_MESSAGE);
redirect(p($post['id']));
}
redirect('/admin/posts/new');
});
/**
* Edit actions
*
* GET /admin/posts/:id/edit
* PUT /admin/posts/:id
*/
get(';^/admin/posts/(?<id>\d+)/edit$;', function($app, $params) {
display('admin/posts/edit');
});
put(';^/admin/posts/(?<id>\d+)$;', function($app, $params) {
if (save($app->post)) {
flash('notice', POST_UPDATED_MESSAGE);
redirect(p($params['id']));
}
redirect(p($params['id']) . '/edit');
});
/**
* Delete actions
*
* GET /admin/posts/:id/delete
* DELETE /admin/posts/:id
*/
get(';^/admin/posts/(?<id>\d+)/delete$;', function($app, $params) {
display('admin/posts/delete');
});
delete(';^/admin/posts/(?<id>\d+)$;', function($app, $params) {
$app->post->delete();
flash('notice', POST_DELETED_MESSAGE);
redirect('/admin/posts');
});