Fix asset URL generation

This is important when Flarum is deployed in a subfolder.

Closes #291.
This commit is contained in:
Franz Liedke 2015-08-29 22:38:31 +02:00
parent 13aed29c26
commit 4a271a7868
2 changed files with 5 additions and 4 deletions

View File

@ -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;
}
/**

View File

@ -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";
}
}