$app->post('/app/create', function () use($app, $twig, $assets, $MongoUser) { $_user = array('_id' => uniqid(), 'email' => $app->request()->post('email'), 'password' => $app->request()->post('password')); $new_user = $MongoUser->save($_user); if ($new_user) { // redirect to login page $dataArray = array('user' => $new_user, 'message' => "User created sucessfully"); //$response = json_encode($dataArray); //echo $response; if (!isset($_SESSION)) { session_start(); } $cookie_data = json_encode($new_user, true); $_SESSION['app_id'] = $cookie_data; $app->redirect('/app'); } else { $app->halt(401, "User sign up fail."); } }); /* $app->get('/app/create', function() use ($app, $twig, $assets) { // so here I need to call the API. echo "hi"; }); */ // this is used as my default function $app->notFound(function () use($app, $twig, $assets) { $data = array('user' => 'testuser', 'test' => 'hahahahha', 'static_url' => $assets); echo $twig->render('views/404.php', $data); }); $app->run();
$collection->attachRoute(new Route('/calendarAction', array('_controller' => 'PaymentController::listPaymentsOnCalendarAction', 'methods' => 'POST'))); $router = new Router($collection); $router->setBasePath('/'); $route = $router->matchCurrentRequest(); // Vamos a usar el PHPRouter para todas las rutas relacionadas a la pagina de la escuela, // y Slim para todas las rutas de la api REST. // Asique si al llegar una ruta vemos que no pertenece al mapeo de PHPRouter, usamos slim. if ($route) { AuthController::checkPermission($route->getAction()); $route->dispatch(); } else { $slimApp = new \Slim\Slim(); // Retorna un arreglo asociativo con las claves "por_pagar" y "pagas". // Cada arreglo dentro de esas 2 cosas contiene los datos de un alumno // http://localhost/cuotasImpagasYPorPagarDe/21/year/2016 << este tiene datos cargados para ver $slimApp->get('/cuotasImpagasYPorPagarDe/:studentID/year/:year', function ($studentID, $year) { FeeService::listPaidAndToBePaidFeesOfStudentInYear($studentID, $year); }); // Devuelve un arreglo de 12 posiciones, cada posicion representa un mes, y contiene la cantidad de ingresos // en ese mes. $slimApp->get('/ingresosTotalesEn/:year', function ($year) { RevenueService::totalRevenueByMonthInYear($year); }); $slimApp->get('/getUsersPosition', function () { //$positions = [[-57.9749, -34.9205], [-57.9799, -34.9305]]; //echo json_encode($positions); StudentService::getStudentsPositions(); }); // Si slim detecta q la ruta no existe, se va a encargar de retornar el codigo de error y lo q necesite. $slimApp->run(); }