Sådan benyttes komponenten TableHeader klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/TableHeader.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? TableHeader::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new TableHeader($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten TableHeader klassen
Den fulde PHP kildekode for TableHeader klassen
<?php/** * @package table * @filesource * @see HTMP_TABLE_COMPONENT_PATH.'/TableHeader.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.'/Htmlspecialchars.php');require_once(HTML_TABLE_COMPONENT_PATH.'/Table.php');require_once(HTML_BASE_UTIL_PATH.'/Images.php');if (defined('HTML_LOG_UTIL_PATH')) { require_once(HTML_LOG_UTIL_PATH.'/Log.php');}/** * Generates a table header * <code> * +------------------------- * | > | Text header | * +------------------------- * | : * Usage: * $datareader = null; * $text = "Text header"; * $width = "100%"; * $class = "theTable"; * $border = "1"; * $cellpadding = "5" * $cellspacing = "0"; * $summary = ""; * $caption = ""; * $id = ""; * * $header = new TableHeader($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); * print $header->getHtml(); * Or * TableHeader::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); * </code> * @package table */class TableHeader extends Table { /** * @var String $text The text heading */ protected $text = ''; /** * @var Image $text The Image object */ protected $image = NULL; /** * Constructor * @param String $text The text header for the table * @param String $width The Width for the table * @param String $class The Class * @param String $border The Border * @param String $cellpadding The CellSpacing * @param String $cellspacing The CellPadding * @param String $summary The Summary * @param String $caption The Caption * @param String $id The element ID */ function __construct($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $id='') { parent::__construct($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); if (defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) { //$this->text = $text != '' ? $text : $this->getClassName().'(), you forgot to add text'; } else { $this->text = trim($text != '' ? $text : ''); } $this->image = NULL; } /** * Return a new content object for table header * @return Object The table header as html */ function newContent() { $tr = new Tr(); $image = $this->newTriangle(IMAGE_ARROW_HEADLINE, ""); if ($this->image != NULL && is_object($this->image)) { $image = $this->image; } $td = new Td(CSS_ARROW_HEADLINE,'middle','', $image); $tr->add($td); $rawvalue = ucfirst(str_replace('_',' ', $this->text)); $text = Htmlspecialchars::encode($rawvalue); $th = new Th(CSS_COLOR_HEADER,'','left', $text); $tr->add($th); return $tr; } /** * Toogle the request parameters which will minimize or maximize this component * You may override this function in order to create the minimize functionality * @abstract * @return array The array of key=>value pair */ function getMinimize() { return array(); // Dymmy stub } /** * Builds the html for a table header, and return it * @return String The table header as html */ function getHtml() { $html = $this->html; if (HTTP_USER_AGENT!=HTTP_USER_AGENT_P900) { if ($this->text != '') { $this->add($this->newContent()); // Render it $html .= $this->getStart(); $html .= $this->getEnd(); } else { $html .= '<!-- No text in TableHeader -->'."\r\n"; } } return $html; } /** * Display html * <code> * Usage: * TableHeader::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); * </code> * @static * @param String $text The text header for the table * @param String $width The Width for the table * @param String $class The Class * @param String $border The Border * @param String $cellpadding The CellSpacing * @param String $cellspacing The CellPadding * @param String $summary The Summary * @param String $caption The Caption * @param String $id The element ID */ public static function display($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $id='') { $html = new TableHeader($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); $html->addHtml(); }}?>
Den fulde HTML kildekode for TableHeader klassen
<? <!-- DEBUG: TableHeader --> <!-- No text in TableHeader --> ?>
Her er 'klasse metoderne' for TableHeader klassen:
Her er 'objekt variable' for TableHeader klassen: