- Fixed the subdirectory loading issue.
Changed: [app/View.php](/Users/tyemeclifford/Documents/GH/blog/app/View.php): generated URLs now honor a base path like /blog. [app/Config.php](/Users/tyemeclifford/Documents/GH/blog/app/Config.php): added base_path support and derives it from base_url or SCRIPT_NAME. [app/App.php](/Users/tyemeclifford/Documents/GH/blog/app/App.php): route parsing strips the base path, and PHP can safely serve theme/upload assets for virtual subdirectory previews. [.htaccess](/Users/tyemeclifford/Documents/GH/blog/.htaccess): removed hardcoded RewriteBase /. [themes/neon/layout.php](/Users/tyemeclifford/Documents/GH/blog/themes/neon/layout.php): root-relative social links like /feed.xml now become /blog/feed.xml. [README.md](/Users/tyemeclifford/Documents/GH/blog/README.md): documented subdirectory setup.
This commit is contained in:
+14
-1
@@ -5,6 +5,14 @@ namespace NeonBlog;
|
||||
|
||||
final class View
|
||||
{
|
||||
private static string $basePath = '';
|
||||
|
||||
public static function setBasePath(string $basePath): void
|
||||
{
|
||||
$basePath = '/' . trim($basePath, '/');
|
||||
self::$basePath = $basePath === '/' ? '' : $basePath;
|
||||
}
|
||||
|
||||
public static function e(mixed $value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
@@ -18,7 +26,12 @@ final class View
|
||||
$path = rtrim($path, '/');
|
||||
}
|
||||
|
||||
return $query === [] ? $path : $path . '?' . http_build_query($query);
|
||||
$url = self::$basePath . $path;
|
||||
if ($url === '') {
|
||||
$url = '/';
|
||||
}
|
||||
|
||||
return $query === [] ? $url : $url . '?' . http_build_query($query);
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $item */
|
||||
|
||||
Reference in New Issue
Block a user