When developing a Joomla 2.5 Component, I have loaded an image using the following function:
public function iconButton( $link, $image ) {
$lang = &JFactory::getLanguage();
$button = '';
if ($lang->isRTL()) {
$button .= '';
} else {
$button .= '';
}
$button .= ''
.'<a href="'.$link.'" target="_blank">'
.JHTML::_('image', 'administrator/components/com_mycomponent/assets/images/'.$image )
.'</a>'
.'';
$button .= '';
return $button;
}
I am now testing this image on a live site and I get the following error message:
Warning: Missing argument 2 for JHtml::image() in ../public_html/libraries/joomla/html/html.php on line 474
Upon investigating the path from the warning I have found the following on line 474:
public static function image($file, $alt, $attribs = null, $relative = false, $path_only = false)
Here is the call on the view which is creating the warning:
echo MyComponentHelper:: iconButton( $link, 'myimage.png' );
This leads me to believe that I need to add the $alt
variable into my custom iconButton
function to clear out this error. I have attempted several variations of this myself but have not yet cracked the code. Any idea on a simple way to clear this out?
The simplest way to clear out the error would be to just add an empty string as an additional parameter:
.JHTML::_('image', 'administrator/components/com_mycomponent/assets/images/'.$image, '')
Obviously, that's not a great alt tag for the image to have, but it shouldn't have an error anymore.
You could also add it as a parameter to the function but set a default value for it in your function, so you could set it appropriately in the future but still clear the error for all existing uses of the function like so:
public function iconButton( $link, $image, $alt='' ) {
$lang = &JFactory::getLanguage();
$button = '';
if ($lang->isRTL()) {
$button .= '';
} else {
$button .= '';
}
$button .= ''
.'<a href="'.$link.'" target="_blank">'
.JHTML::_('image', 'administrator/components/com_mycomponent/assets/images/'.$image, $alt )
.'</a>'
.'';
$button .= '';
return $button;
}