how to build custom URL

Status
Not open for further replies.

sunnyjey

Active Member
I want to display the Photo as an Avatar. I have created the image Plugin.

I need to build the URL path for the image from another table. The URL should be:

https://www.mydomain.com/media/reviews/photos/rel_path/filename.extension

WHERE rel_path, filename and extension (jpg/jpeg/png) are Column Names from the Third Table.

View attachment 17256

I have created calc element with following code:

Code:
$url ='{$jConfig_live_site}media/reviews/photos/';
$photo = 'photo';

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
  ->select('rel_path, filename')
  ->from('mytable2_media')
  ->where('user_id = ' . $myDb->quote('{mytable1___userid_raw}'). ' and media_type = ' . $myDb->quote($photo));
$myDb->setQuery($myQuery);
$media = $myDb->loadResult();


return $url . $media ;

How do I select rel_path, filename and extension and construct the URL ?
 
Code:
$url = JPATH_SITE . '/media/reviews/photos/';
$photo = 'photo';

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
  ->select('rel_path, filename')
  ->from('mytable2_media')
  ->where('user_id = ' . $myDb->quote('{mytable1___userid_raw}'). ' and media_type = ' . $myDb->quote($photo));
$myDb->setQuery($myQuery);
$media = $myDb->loadObject();

return $url . $media->rel_path . $media->filename;

Of course, if you want that to be an actual IMG tag, you'll need to build that in the return ...

Code:
return '<img src="' . $url . $media->rel_path . $media->filename . '" />';

You can also add size attributes to the img if need be.

-- hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top