From 1d1cc9e4430f1f68e003ef7d11cc732a079125e5 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Sat, 29 Aug 2015 22:38:31 +0200 Subject: [PATCH] Fix asset URL generation This is important when Flarum is deployed in a subfolder. Closes #291. --- src/Core/Users/User.php | 2 +- src/Http/UrlGenerator.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Core/Users/User.php b/src/Core/Users/User.php index 2265f45f4..da2a0aa19 100755 --- a/src/Core/Users/User.php +++ b/src/Core/Users/User.php @@ -306,7 +306,7 @@ class User extends Model { $urlGenerator = app('Flarum\Http\UrlGeneratorInterface'); - return $this->avatar_path ? $urlGenerator->toAsset('assets/avatars/'.$this->avatar_path) : null; + return $this->avatar_path ? $urlGenerator->toAsset('avatars/'.$this->avatar_path) : null; } /** diff --git a/src/Http/UrlGenerator.php b/src/Http/UrlGenerator.php index 22791adfb..6383df3d9 100644 --- a/src/Http/UrlGenerator.php +++ b/src/Http/UrlGenerator.php @@ -11,6 +11,8 @@ namespace Flarum\Http; +use Flarum\Core; + class UrlGenerator implements UrlGeneratorInterface { protected $routes; @@ -26,12 +28,11 @@ class UrlGenerator implements UrlGeneratorInterface $path = $this->routes->getPath($name, $parameters); $path = ltrim($path, '/'); - // TODO: Prepend real base URL - return "/$path"; + return Core::url() . "/$path"; } public function toAsset($path) { - return "/$path"; + return Core::url() . "/assets/$path"; } }