-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathapp.php
109 lines (100 loc) · 2.44 KB
/
app.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* Local variables
* @var \Phalcon\Mvc\Micro $app
*/
use Phalcon\Mvc\Controller;
use Phalcon\Mvc\Micro\Collection as MicroCollection;
/**
* ACL checks
*/
$app->before(new AccessMiddleware());
/**
* Insert your Routes below
*/
/**
* Index
*/
$index = new MicroCollection();
$index->setHandler('IndexController', true);
// Gets index
$index->get('/', 'index');
// Authenticates a user
$index->post('/authenticate', 'login');
// logout
$index->get('/logout', 'logout');
// Adds index routes to $app
$app->mount($index);
/**
* Profile
*/
$profile = new MicroCollection();
$profile->setHandler('ProfileController', true);
$profile->setPrefix('/profile');
// Gets profile
$profile->get('/', 'index');
// // Updates user profile
$profile->patch('/update', 'update');
// Changes user password
$profile->patch('/change-password', 'changePassword');
// Adds profile routes to $app
$app->mount($profile);
/**
* Users
*/
$users = new MicroCollection();
$users->setHandler('UsersController', true);
$users->setPrefix('/users');
// Gets all users
$users->get('/', 'index');
// Creates a new user
$users->post('/create', 'create');
// Gets user based on unique key
$users->get('/get/{id}', 'get');
// Updates user based on unique key
$users->patch('/update/{id}', 'update');
// Changes user password
$users->patch('/change-password/{id}', 'changePassword');
// Deletes user based on unique key
$users->delete('/delete/{id}', 'delete');
// Adds users routes to $app
$app->mount($users);
/**
* Cities
*/
$cities = new MicroCollection();
$cities->setHandler('CitiesController', true);
$cities->setPrefix('/cities');
// Gets cities
$cities->get('/', 'index');
// Creates a new city
$cities->post('/create', 'create');
// Gets city based on unique key
$cities->get('/get/{id}', 'get');
// Updates city based on unique key
$cities->patch('/update/{id}', 'update');
// Deletes city based on unique key
$cities->delete('/delete/{id}', 'delete');
// Adds cities routes to $app
$app->mount($cities);
/**
* Not found handler
*/
$app->notFound(function () use ($app) {
$app->response->setStatusCode(404, 'Not Found')->sendHeaders();
$app->response->setContentType('application/json', 'UTF-8');
$app->response->setJsonContent(array(
'status' => 'error',
'code' => '404',
'messages' => 'URL Not found',
));
$app->response->send();
});
/**
* Error handler
*/
$app->error(
function ($exception) {
print_r('An error has occurred');
}
);