Sådan benyttes komponenten Rowcolor klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/Rowcolor.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? Rowcolor::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new Rowcolor($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten Rowcolor klassen
Den fulde PHP kildekode for Rowcolor klassen
<?php/** * @package basic * @see HTML_BASIC_UTIL_PATH.'/Rowcolor.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 *//** * Generates a new Row Color * <code> * Usage: * $html = new Rowcolor($count++,, $light, $dark); * print $html->getHtml(); * Or * $rowcolor = Rowcolor::get($count++, $light, $dark); * Or * $imgcolor = Rowcolor::img($color); * </code> * @package basic */class Rowcolor { /** * @var int $count The row counter */ protected $count = 0; /** * @var String $light The light row */ protected $light = 0; /** * @var String $dark The dark row */ protected $dark = 0; /** * Constructor * @param int $count The next row * @param String $light The light row * @param String $dark The dark row */ function __construct($count, $light='', $dark='') { $this->count = $count; $this->light = $light != ''?$light:CSS_COLOR_LIGHT; $this->dark = $dark != ''?$dark :CSS_COLOR_DARK; } /** * Get the complete html for a Row Color * @see CSS_COLOR_LIGHT The css color Light * @see CSS_COLOR_DARK The css color Dark * @return String the html */ function getHtml() { return $this->count%2?$this->light:$this->dark; } /** * Returns 6 digits css color code from the supplied 3 digits hex color * The color is hex I.e. 1F3 => 11FF34 (where the last color digit is counted one up) * This function ia a bugfix for xhtml 1.0 strict compliant validator * where <img border="0" ... /> is not allowed, however we must have it * <code> * Usage: * $imgcolor = Rowcolor::img($color); * </code> * @static * @param int $hexcolor The css hex color, i.e. a2b * @return String the img css color (6 digits) i.e. 'aa22bc' (c=b+1) */ public static function img($hexcolor) { $html = ''; $len = strlen($hexcolor); if ($len != 3) { //die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".' Rowcolor::img($hexcolor), The color MUST be 3 digits, like 2fc, found length='.$len.' in $hexcolor='.$hexcolor); } for ($i = 0; $i < $len; $i++) { $digit = hexdec(substr($hexcolor, $i, 1)); if (!is_numeric($digit)) { die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".' Rowcolor::img($hexcolor), The color is not a numeric, found $digit='.$digit.' in $hexcolor='.$hexcolor); } switch ($i) { case 0: case 1: $html .= ''.dechex($digit).dechex($digit); break; case 4: case 3: case 2: $html .= ''.dechex($digit); if ($digit + 1 > 0xF) { $html .= dechex($digit - 1); } else { $html .= dechex($digit + 1); } break; default: //die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".', Rowcolor::img($hexcolor), Should never end up here!'); break; } } return $html; } /** * Get the rowcolor for the odd/even count * <code> * Usage: * Rowcolor::get($count++, $light, $dark); * </code> * @static * @param int $count The next row * @param String $light The light row * @param String $dark The dark row * @return String the html */ public static function get($count, $light='', $dark='') { $html = new Rowcolor($count, $light, $dark); return $html->getHtml(); }}?>
Den fulde HTML kildekode for Rowcolor klassen
<? baseColorLight ?>
Her er 'klasse metoderne' for Rowcolor klassen:
Her er 'objekt variable' for Rowcolor klassen: