You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a new method like express.use() to pass down frequently used variables like database or other class instances, because when working with many routes, writing many variables with the use statement becomes a bit too much.
Example:
$database = new Database();
$router->use($database);
$router->get('/user/{id}', function ($id) {
$user = $database->query("SELECT * FROM users WHERE id = ?", [$id]);
if ($user) {
echo json_encode($user);
} else {
echo "User not found";
}
});
The text was updated successfully, but these errors were encountered:
Add a new method like express.use() to pass down frequently used variables like database or other class instances, because when working with many routes, writing many variables with the use statement becomes a bit too much.
Example:
The text was updated successfully, but these errors were encountered: