Sådan benyttes komponenten Image klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/Image.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? Image::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new Image($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten Image klassen
Den fulde PHP kildekode for Image klassen
<?php/** * @package base * @see HTML_BASE_UTIL_PATH.'/Image.php' * @copyright (c) http://Finn-Rasmussen.com * @license http://Finn-Rasmussen.com/license/ myPHP License conditions * @author http://Finn-Rasmussen.com * @version 1.11 * @since 27-nov-2009 *//** * The required files */require_once(HTML_BASE_UTIL_PATH.'/Img.php');if (defined('HTML_UTIL_COMPONENT_PATH')) { require_once(HTML_UTIL_COMPONENT_PATH.'/Url.php');}if (defined('HTML_LOG_UTIL_PATH')) { require_once(HTML_LOG_UTIL_PATH.'/Log.php');}/** * Returns a complete Image as HTML * The images are expected to be located here: /images/*.gif * Note: If you specify "\r\n" in the alt tag, then a break is automatically added * <code> * <img name="$name" src="$src" width="$width" height="$height" * alt="$alt" class="$class" border="$border" /> * Usage: * $image = new Image($src, $width, $height, $alt, $class, $border, $aux); * print $image->getHtml(); * Or * Image::display($src, $width, $height, $alt, $class, $border, $aux); * </code> * @package base */class Image extends Img { /** * Constructor * @param String $src The source path for the image i.e. /logo.gif * @param String $width The width or null or '' * @param String $height The height or null or '' * @param String $alt The alt text * @param String $class The css class for the image * @param String $border The border of an image * @param String $aux The new line indicator (nl) * * @global String IMAGE_SKIN_URL Defines the relative sub url from docroot * @global String PROJECT_PATH Defines the full path on the disk to the Project docroot */ function __construct($src='', $width='', $height='', $alt='', $class='', $border='', $aux='') { $theSrc = $src; $strHttp = 'http:/'.'/'; $strHttps = 'https:/'.'/'; if (strpos($src, $strHttp) !==false || strpos($src, $strHttps)!==false || strpos($src, CURRENT_MYPHP_VERSION )!==false || substr($src,0,1)==="." ) { // remote server or './*' or '../*' } else { $domainname = ''; if (defined('HTML_UTIL_COMPONENT_PATH')) { $strHttp = 'http:/'.'/'; if (strpos($src, $strHttp)!==false) { // Skip } else { $domainname = Url::subdomain(DOMAIN_NAME); // Strip off subdomain names } } $theSrc = $domainname.IMAGE_SKIN_URL.$src; // Local server } parent::__construct($theSrc, $width, $height, $alt, $class, $border, $aux); } /** * Get the name of the src file, where the IMAGE_SKIN_URL is stripped off * Except if the domain name is part of the src * @return String The name of the gif file */ function getSrcName() { return $this->get('src'); //str_replace(IMAGE_SKIN_URL,'', $this->get('src')); } /** * Display html * <code> * Usage: * Image::display($src, $width, $height, $alt, $class, $border, $aux); * </code> * @static * @param String $src The source path for the image * @param String $width The width or null or '' * @param String $height The height or null or '' * @param String $alt The alt text * @param String $class The css class for the image * @param String $border The border of an image * @param String $aux The new line indicator (nl) */ public static function display($src='', $width='', $height='', $alt='', $class='', $border='', $aux='') { $html = new Image($src, $width, $height, $alt, $class, $border, $aux); $html->addHtml(); }}?>
Den fulde HTML kildekode for Image klassen
<? <!-- DEBUG: Image --> <img src="http://finnrasmussen.dk/images/aniBee.gif" width="20" height="20" alt="Sample demo" /> ?>
Her er 'klasse metoderne' for Image klassen:
Her er 'objekt variable' for Image klassen: