Ejemplo n.º 1
0
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
session_start();
$app = new \Slim\Slim();
$authenticate = function ($app) {
    return function () use($app) {
        if (!isset($_SESSION['user'])) {
            $app->redirect('/login');
        }
    };
};
//Get Method to get the data from database
$app->get('/student(/:id)', $authenticate($app), function ($id = null) use($app, $db) {
    if ($id == null) {
        $data = array();
        foreach ($db->student() as $p) {
            $data[] = array('student_id' => $p['student_id'], 'name' => $p['name'], 'birthday' => $p['birthday'], 'sex' => $p['sex'], 'religion' => $p['religion'], 'blood_group' => $p['blood_group'], 'address' => $p['address'], 'phone' => $p['phone'], 'email' => $p['email'], 'father_name' => $p['father_name'], 'mother_name' => $p['mother_name'], 'rollno' => $p['roll'], 'transport_id' => $p['transport_id']);
        }
    } else {
        $data = null;
        if ($p = $db->student()->where('student_id', $id)->fetch()) {
            $data = array('student_id' => $p['student_id'], 'name' => $p['name'], 'birthday' => $p['birthday'], 'sex' => $p['sex'], 'religion' => $p['religion'], 'blood_group' => $p['blood_group'], 'address' => $p['address'], 'phone' => $p['phone'], 'email' => $p['email'], 'father_name' => $p['father_name'], 'mother_name' => $p['mother_name'], 'rollno' => $p['roll'], 'transport_id' => $p['transport_id']);
        }
    }
    $app->response()->header('content-type', 'application/json');
    echo json_encode($data);
});
$app->get('/search(/:name)', function ($name = null) use($app, $db) {
    if ($name == null) {
        $data = array();
    } else {