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