Understanding Embedded URL Generation

capt_kirk

Joined: 2006-01-24
Posts: 492
Posted: Tue, 2007-08-14 14:33

Valiant (or someone else who understands this),

I've working on refactoring G2Image to add LightBox support among other things. I've figured out how to use the URL generator to get derivatives, but the URL that I'm getting is a little strange.

In the embedding initialization, I'm using (from WPG2's options table)

$option["g2Uri"] = http://localhost/gallery2/
$option["embedUri"] = http://localhost/wordpress/index.php/wpg2

I would expect a URL for a thumbnail or a resize to look something like

/wordpress/index.php/wpg2?g2_itemId=28

But I'm only getting

wpg2?g2_itemId=28

Do you have any quick insight into why this is happening? If not, I'll dive into the code, but I was hoping you could save me some time.

Thanks,
Kirk

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2007-08-14 17:02

This has to do with PHP PathInfo (index.php/wpg2) and how G2 interprets the embedUri.
The specs: everything up to the last "/" is interpreted as the path part.
That's the "/wordpress/index.php/" part in your case.

And G2's url generator tries to generate relative URLs (because they're shorter) by default. So G2 thinks that it can drop the index.php part.
But it only drops the "/wordpress/index.php/" part if that's part of the current request_uri as well.

And that's fine, usually.
The browser sees the URL "wpg2?g2_itemId=28" and it's currently at "http://localhost/wordpress/index.php/foo", thus it knows that the actual URL is "http://localhost/wordpress/index.php/" + "wpg2?g2_itemId=28".

If you're working out of the normal context and need server-relative or even full URLs, use the appropriate URL generator options.

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
capt_kirk

Joined: 2006-01-24
Posts: 492
Posted: Tue, 2007-08-14 17:19

Thanks. This did the trick:

$thumbnailUrl = $urlGenerator->generateUrl(array('view' => 'core.ShowItem', 'itemId' => $item->getid()), array('forceServerRelativeUrl' => true));

It gave me the full embedded URL I was looking for.