<?php use App\Models\User; use App\Controllers\UserController; $app->get('/', function () use($app) { $user = new User(); $app->render('home.php', ['name' => $user->name]); })->name('home'); $app->get('/users', function () use($app) { $users = new UserController(); print_r($users->getAllUsers()); }); $app->get('/users/:id', function ($id) use($app) { $users = new UserController(); print_r($users->getUsers($id)); });
<?php use App\Controllers\BlogController; use App\Controllers\UserController; $app->group('/blogs', function () { $this->get('', function ($request, $response, $args) { $blogs = BlogController::allBlogs(); $response->withHeader('Content-Type', 'application/json')->write($blogs); }); $this->get('/{id}', function ($request, $response, $args) { $blog = BlogController::fetch($args['id']); $response->withHeader('Content-Type', 'application/json')->write($blog); }); }); $app->group('/users', function () { $this->get('', function ($request, $response, $args) { $users = UserController::allUsers(); $response->withHeader('Content-Type', 'application/json')->write($users); }); $this->get('/{id}', function ($request, $response, $args) { $user = UserController::fetch($args['id']); $response->withHeader('Content-Type', 'application/json')->write($user); }); });