Skip to content

Commit 69f5a3d

Browse files
added flash message to redirect
1 parent 41d2ff8 commit 69f5a3d

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

init.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
session_start();
23

34
// Pre requires
45
require_once __DIR__ . '/vendor/autoload.php';

scripts/functions/functions.script.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,7 @@ function redirect($name, array $vars = [], $message = null)
137137
$query = (!empty($vars)) ? '?' . flatenAssocArray($vars, false) : '';
138138

139139
$route = $target . $query;
140+
141+
if ($message) $_SESSION['flash_msg'] = $message;
140142
header('Location: ' . $route);
141-
}
143+
}

scripts/functions/router.script.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ private static function app_route($path, $vars = [])
1616
{
1717
$routes = APP_ROUTES[$_SERVER['REQUEST_METHOD']];
1818

19+
$flash_msg = null;
20+
if (isset($_SESSION['flash_msg'])) {
21+
$flash_msg = $_SESSION['flash_msg'];
22+
unset($_SESSION['flash_msg']);
23+
}
24+
1925
// Include the header partial
2026
require_once APP_TEMPLATES . 'partials/header.php';
2127

@@ -55,7 +61,6 @@ private static function api_route($path)
5561
public static function route($uri, $vars = [])
5662
{
5763
$path = preg_replace('/' . preg_quote($_ENV['APP_ROUTE_ROOT'], '/') . '/', '', $uri, 1);
58-
5964
$parts = explode('/', $path);
6065

6166
if ($parts[1] == 'api') {

views/index.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,4 @@
22
<h2>HOME PAGE</h1>
33
<p>Welcome to the Home page, <b>Route:</b> <code><?= enroute('get:root') ?></code></p>
44
<small class="text-secondary">Generated from <?= $_ENV['APP_NAME'] ?></small>
5-
6-
<?php
7-
$db = new DataBase();
8-
// $db->update('login', [
9-
// 'user' => 'somename',
10-
// 'email' => 'user@email.com'
11-
// ], 'id = "unknown" && date = "NULL" || die');
12-
?>
135
</div>

0 commit comments

Comments
 (0)