tdudzik
tdudzik

Reputation: 391

Why UrlGenerator generate path without host and scheme in Silex?

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

Answers (2)

Raphaël Malié
Raphaël Malié

Reputation: 4012

To generate an absolute URL you have to do that :

$app['url_generator']->generate('blog.posts.index', [], UrlGeneratorInterface::ABSOLUTE_URL);

Upvotes: 11

Jonathan Pasquier
Jonathan Pasquier

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

Related Questions