Sådan benyttes komponenten Th klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/Th.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? Th::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new Th($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten Th klassen
Den fulde PHP kildekode for Th klassen
<?php/** * @package table * @filesource * @see HTML_TABLE_COMPONENT_PATH.'/Th.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_COMMON_PATH.'/Html.php');require_once(HTML_BASE_UTIL_PATH.'/Raw.php');/** * The Table Header Data. * Generates a table Header column * <code> * +-------------------------------- * | header_1 | * +-------------------------------- * Usage: * $text = 'plain text'; // Optionally * $th = new Th($class, $valign, $align, $text); * print $th->getHtml(); * Or * $th= new Th($class, $valign, $align); * print $th->getStart(); * : * print $th->getEnd(); * Or * Th::display($class, $valign, $align, $text); * Or * Th::start($class, $valign, $align); * Raw::display($text); * Th::end(); * Or * $object = new Raw($text); * $th = new Th($class, $valign, $align, $object); * print $th->getHtml(); * Or * Th::display($class, $valign, $align, $object); * Or * Th::start($class, $valign, $align); * : * Th::end(); * </code> * @package table */class Th extends Html { /** * @var String $class The CSS class name for the TH */ protected $class = ''; /** * @var String $valign The html THr valign attribute */ protected $valign = ''; /** * @var String $align The html TH align attribute */ protected $align = ''; /** * Constructor * @param String $class The class name * @param String $valign The valignment of data * @param String $align The alignment of data * @param String $text The plain text or an object (optionally) */ function __construct($class='', $valign='', $align='', $text='') { parent::__construct(); $this->class = $class != '' ? $class : ''; $this->valign = $valign != '' ? $valign : 'top'; $this->align = $align != '' ? $align : ''; if ($text!= '') { if (is_object($text)) { $this->add($text); } else { $this->add(new Raw($text)); // Plain text object } } else { // Ignore } } /** * Get the start html for a TH * @return String the html */ function getStart() { $html = ' <th'; $html .= $this->getAttribute('class'); $html .= $this->getAttribute('valign'); $html .= $this->getAttribute('align'); $html .= ">"; $elements = $this->getElements(); if ($elements != '') { $html .= $elements; } else { $html .= ' '; } return $html; } /** * Get the end html for a TH * @return String the html */ function getEnd() { return "</th>\r\n"; } /** * Get the complete html for a TH * @return String the html */ function getHtml() { $html = ''; $html .= $this->getStart(); $html .= $this->getEnd(); return $html; } /** * Get the start of the tag * <code> * Usage: * Th::start($class , $valign, $align, $text); * </code> * @static * @param String $class The class name * @param String $valign The valignment of data * @param String $align The alignment of data * @param String $text The plain text or an object (optionally) */ public static function start($class='' , $valign='', $align='', $text='') { $html = new Th($class, $valign, $align, $text); $html->addHtml($html->getStart()); } /** * Get the end of the tag * <code> * Usage: * Th::end(); * </code> * @static */ public static function end() { $html = new Th(); $html->addHtml($html->getEnd()); } /** * Display html * <code> * Usage: * Th::display($class, $valign, $align, $text); * </code> * @static * @param String $class The class name * @param String $valign The valignment of data * @param String $align The alignment of data * @param String $text The plain text or an object (optionally) */ public static function display($class='', $valign='', $align='', $text='') { $html = new Th($class, $valign, $align, $text); $html->addHtml(); }}?>
Den fulde HTML kildekode for Th klassen
<? <th valign="top"> </th> ?>
Her er 'klasse metoderne' for Th klassen:
Her er 'objekt variable' for Th klassen: