I would like to make the following function available throughout my routers.
public function getAll($request, $response, $args, $table, $prefix, $order, $PermRead) {
// retrieve all records
// WORKING... Security questions
// 1. First, check to make sure authenticated (via JSESSION_ID, etc.)
// 2. Automatically apply site_id to ALL queries
// 3. Apply sch_id to this query
// 4. Get permissions
$status = null;
$site_id = $sch_id = 1;
if (!$PermRead) {
$status = 403; // 403 Forbidden
} else {
$sql =
"SELECT * from " . $table .
" WHERE " . $prefix . "_site_id = " . $site_id .
" AND " . $prefix . "_sch_id = " . $sch_id .
" AND " . $prefix . "_deleted_timestamp IS NULL " .
" ORDER BY " . $order;
$rows = $this->dbw->run($sql);
}
if (!$status) {
$status = 200; // 200 OK
}
return $response->withStatus($status)->withJson($rows);
}
However, I get the following error: Fatal error: Using $this when not in object context in C:\Wamp\wwwavine\server\srcoutes.php on line 26
How should I make this function available so that I can call it inside my route, like this:
// retrieve all classroom records
$app->get('/classrooms', function ($request, $response, $args) {
$PermRead = true; // check permissions
return getAll($request, $response, $args, "classroom", "room", "room_name", $PermRead);
});