Sådan benyttes komponenten Textarea klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/Textarea.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? Textarea::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new Textarea($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten Textarea klassen
Den fulde PHP kildekode for Textarea klassen
<?php/** * @package form * @filesource * @see HTML_FORM_COMPONENT_PATH.'/Textarea.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.'/Element.php');require_once(HTML_BASE_UTIL_PATH.'/Tabindex.php');require_once(HTML_BASE_UTIL_PATH.'/Accesskey.php');/** * Generates a html form elements, TEXTAREA * <code> * Usage: * $textarea = new Textarea($name, $text, $rows, $cols, $class, $title, $tabindex, $accesskey, $wrap); * print $textarea->getHtml(); * Or * $textarea = new Textarea($name, $text, $rows, $cols, $class, $title, $tabindex, $accesskey, $wrap); * print $textarea->getStart(); * print "Display some text"; * print $textarea->getEnd(); * Or * Textarea::display($name, $text, $rows, $cols, $class, $title, $tabindex, $accesskey, $wrap); * Or * Textarea::start($name, $text, $rows, $cols, $class, $title, $tabindex, $accesskey, $wrap); * Raw::display('Display some text'); * Textarea::end(); * </code> * @package form */class Textarea extends Element { /** * @var String $rows The number of rows */ protected $rows = ''; /** * @var String $cols The number of columns */ protected $cols = ''; /** * The wrap attribute defines how the text is wrapped inside the text area. * If set to off, the user have to scroll to see long lines * If set to physical, the lines are broken and is sent as seen by the user * If set to virtual, the text is wrapped within the text area, however the text is sent unbroken to the server. * @var String $wrap One of the following values '', off, physical or virtual */ protected $wrap = ''; /** * Constructor * @param String $name The name of the control * @param String $text The text value, if any * @param String $rows The number of rows * @param String $cols The number of columns * @param String $class The class name * @param String $title The title * @param String $tabindex The tabindex * @param String $accesskey The accesskey * @param String $wrap The wrap (virtual,physical,off) */ function __construct($name, $text='', $rows='', $cols='', $class='', $title='', $tabindex='', $accesskey='', $wrap='') { $aClass = $class != '' ? $class : CSS_TEXTAREA_CLASS; $onclick = ''; $aTabindex = $tabindex != '' ? $tabindex : Tabindex::next(); // Call the constructor parent::__construct($name, $text, $aClass, $title, $aTabindex, $onclick, $accesskey); $this->rows = $rows != '' ? $rows : TEXTAREA_ROWS; $this->cols = $cols != '' ? $cols : TEXTAREA_COLS; $this->wrap = $wrap != '' ? $wrap : TEXTAREA_WRAP_NONE; switch($this->wrap) { case TEXTAREA_WRAP_NONE: case TEXTAREA_WRAP_OFF: case TEXTAREA_WRAP_VIRTUAL: case TEXTAREA_WRAP_PHYSICAL: // Ok break; default: die($this->getClassName()." Unknown wrap attribute, expected TEXTAREA_WRAP_PHYSICAL etc., found: ".$this->wrap); break; } } /** * Returns the complete html for the start of a textarea control * @return String the complete html */ function getStart() { $html = $this->html; $html .= '<textarea'; $html .= $this->getAttribute('name'); $html .= $this->getAttribute('id'); $html .= $this->getAttribute('rows'); $html .= $this->getAttribute('cols'); $html .= $this->getAttribute('class'); $html .= $this->getAttribute('title'); $html .= $this->getAttribute('tabindex'); $html .= $this->getAttribute('accesskey'); $html .= $this->getAttribute('wrap'); $html .= ">"; // Special handling of the value attribute $encode = false; $stripHttp = false; $html .= $this->getValue($encode, $stripHttp, __FILE__, __LINE__); //$html .= $this->value; return $html; } /** * Returns the complete html for the end of a textarea control * @return String the complete html */ function getEnd() { $html = ''; $html .= "</textarea><br />\r\n"; return $html; } /** * Returns the complete html for a textarea control * @return String the complete html */ function getHtml() { $html = ''; $html .= $this->getStart(); $html .= $this->getEnd(); return $html; } /** * Display start html * <code> * Usage: * Textarea::start($name, $text, $rows, $cols, $class, $title, $tabindex, $accesskey, $wrap); * </code> * @static * @param String $name The name of the control * @param String $text The text value, if any * @param String $rows The number of rows * @param String $cols The number of columns * @param String $class The class name * @param String $tabindex The tabindex * @param String $accesskey The accesskey * @param String $wrap The wrap (virtual,physical,off) */ public static function start($name, $text='', $rows='', $cols='', $class='', $title='', $tabindex='', $accesskey='', $wrap='') { $html = new Textarea($name, $text, $rows, $cols, $class, $title, $tabindex, $accesskey, $wrap); $html->addHtml($html->getStart()); } /** * Display end html * <code> * Usage: * Textarea::end(); * </code> * @static */ public static function end() { $html = new Textarea(); $html->addHtml($html->getEnd()); } /** * Display html * <code> * Usage: * Textarea::display($name, $text, $rows, $cols, $class, $title, $tabindex, $accesskey, $wrap); * </code> * @static * @param String $name The name of the control * @param String $text The text value, if any * @param String $rows The number of rows * @param String $cols The number of columns * @param String $class The class name * @param String $title The title * @param String $tabindex The tabindex * @param String $accesskey The accesskey * @param String $wrap The wrap (virtual,physical,off) */ public static function display($name, $text='', $rows='', $cols='', $class='', $title='', $tabindex='', $accesskey='', $wrap='') { $html = new Textarea($name, $text, $rows, $cols, $class, $title, $tabindex, $accesskey, $wrap); $html->addHtml(); }}?>
Den fulde HTML kildekode for Textarea klassen
<? <!-- DEBUG: Textarea --> <textarea name="Test" rows="5" cols="35" class="formXLARGE baseBorder baseBody" tabindex="1"></textarea><br /> ?>
Her er 'klasse metoderne' for Textarea klassen:
Her er 'objekt variable' for Textarea klassen: