Reputation: 391
I try to generate url with UrlGenerator in Silex but it seems that UrlGenerator generates only content of $_SERVER['REQUEST_URI']
without http://localhost
. So instead of http://localhost/silex/rest-blog/web/blog/posts
I have /silex/rest-blog/web/blog/posts
. Do you have any idea why?
My code:
$app['url_generator']->generate('blog.posts.index');
Upvotes: 2
Views: 1429
Reputation: 4012
To generate an absolute URL you have to do that :
$app['url_generator']->generate('blog.posts.index', [], UrlGeneratorInterface::ABSOLUTE_URL);
Upvotes: 11
Reputation: 2591
The solution proposed by @raphaël-malié is not working for me (Silex 1.3)
Digging through the UrlGenerator documentation, I've come with the following solution:
$url = $app["url_generator"]->generate("blog.posts.index", array(), $app["url_generator"]::ABSOLUTE_URL);
Upvotes: 2