0

Currently I am on my local server and the URL I want to create is:

http://localhost/cax2017/images/flexicontent/l_thecaxton.jpg

/cax2017/images/flexicontent/l_thecaxton.jpg is created by:

FlexicontentFields::getFieldDisplay($item, 'image', null, 'display_large_src', 'item');

If I use:

$url = JURI::base().FlexicontentFields::getFieldDisplay($item, 'image', null, 'display_large_src', 'item');

It fails as I get double /cax2017/cax2017/: http://localhost/cax2017/cax2017/images/flexicontent/l_thecaxton.jpg

I'm looking for a way to make it portable across hosts or servers.

I have solved it with this:

$siteURL='http'.(empty($_SERVER['HTTPS'])?'':'s').'://'.$_SERVER['SERVER_NAME'];

$url = $siteURL.FlexicontentFields::getFieldDisplay($item, 'image', null, 'display_large_src', 'item');

echo $url;

But is there a simpler Joomla way to do it?

1

I suspect it already does what you want.

Throughout code for Flexicontent, they generate links using JURI::base(true) and JURI::root(true). This is the same as JURI::base() and JURI::root(), but returns the absolute path only rather than the absolute link.

The double /cax2017/cax2017/ would certainly be consistant with this, so I assume the getFieldDisplay function works like this.

This approach means that you can move it to a different host without any issue - the links should update the path automatically when you set the new configuration file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.