Skip to content

Commit

Permalink
[ENH] get formatted route path via function
Browse files Browse the repository at this point in the history
  • Loading branch information
bim-g committed Feb 26, 2024
1 parent 7fcda6b commit 047caa0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
9 changes: 9 additions & 0 deletions config/function.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,13 @@ function tra(string $message, $value = null): string
$i18n = new i18n(Session::get('lang'));
$translate_value = !is_array($value) ? [$value] : $value;
return $i18n->translate($message, $translate_value);
}

/**
* get a formatted application route path
* @param string $path
* @return string
*/
function route_path(string $path): string{
return WEB_ROOT . ltrim($path,'/');
}
3 changes: 1 addition & 2 deletions config/globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@
'lang' => 'fr',
'vendor' => true,
'autoload' => ['src', 'controller', 'middleware', 'models', 'helpers'],
'helper' => WEB_ROOT,
'preferences' => WEB_ROOT . 'helper'
'helpers' => WEB_ROOT,
];
2 changes: 1 addition & 1 deletion views/404.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<body>
<div class="w3-margin w3-center">
<h1 class="w3-text-green ">404</h1>
<p><a href="<?= WEB_ROOT ?>">Go home</a></p>
<p><a href="<?= route_path('/') ?>">Go home</a></p>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion views/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<?php } ?>
<div class="w3-card w3-border w3-round-large " style="width: 300px;overflow: hidden">
<h3 class="w3-text-blue-gray w3-padding"><?= $language->translate("Change the language") ?></h3>
<form action="<?= WEB_ROOT . "changelang" ?>" method="post">
<form action="<?= route_path("/changelang") ?>" method="post">
<input type="hidden" name="token" value="<?= Token::generate() ?>">
<select name="lang" id="lang_id" class="w3-select w3-center">
<option value="" class="w3-center w3-large" disabled selected><?= $lang ?></option>
Expand Down

0 comments on commit 047caa0

Please sign in to comment.