Sådan benyttes komponenten Radio klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/Radio.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? Radio::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new Radio($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten Radio klassen
Den fulde PHP kildekode for Radio klassen
<?php/** * @package form * @filesource * @see HTML_FORM_COMPONENT_PATH.'/Radio.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_FORM_COMPONENT_PATH.'/Input.php');/** * Generates an INPUT element for a form, which is a Radio control * <code> * <input type="radio" name="$name" value="$value" title="$title" tabindex="" disabled="disabled" * class="$class" checked="$checked" onclick="alert('Hello')" accesskey="$accesskey" /> * Usage: * $radio = new Radio($name, $value, $class, $checked, $disabled, $onclick, $title, $tabindex, $accesskey); * print $radio->getHtml(); * Or * Radio::display($name, $value, $class, $checked, $disabled, $onclick, $title, $tabindex, $accesskey); * </code> * Note: If you use the onclick facility, then use double quotes outside, and use single quotes inside * Example: Radio::display($name, $value, $class, $checked, $disabled, "alert('hei');"); * @package form */class Radio extends Input { /** * Constructor * @param String $name The name * @param String $value The value, if any * @param String $class The class * @param String $checked The checked, if present * @param String $disabled The disabled * @param String $onclick On click event for javascript * @param String $title The tooltip * @param String $tabindex The tabindex * @param String $accesskey The accesskey */ function __construct($name, $value='', $class='', $checked='', $disabled='', $onclick='', $title='', $tabindex='', $accesskey='') { $aClass = $class != '' ? $class : CSS_RADIO_CLASS; $size = $checked; // Use the size as a placeholder for the checked attribute $maxlength = ''; // Not supported $readonly = ''; // Not supported $aValue = $value != '' ? $value : ''; if ($aValue == '' && $onclick != '') { $aValue = 'notUsed'; } parent::__construct('radio', $name, $aValue, $aClass, $size, $maxlength, $disabled, $readonly, $onclick, $title, $tabindex, $accesskey); } /** * Display html * <code> * Usage: * Radio::display($name, $value, $class, $checked, $disabled, $onclick, $title, $tabindex, $accesskey); * </code> * @static * @param String $name The name * @param String $value The value, if any * @param String $class The class * @param String $checked The checked, if present * @param String $disabled The disabled * @param String $onclick On click event for javascript * @param String $title The tooltip * @param String $tabindex The tabindex * @param String $accesskey The accesskey */ public static function display($name='', $value='', $class='', $checked='', $disabled='', $onclick='', $title='', $tabindex='', $accesskey='') { $html = new Radio($name, $value, $class, $checked, $disabled, $onclick, $title, $tabindex, $accesskey); $html->addHtml(); }}?>
Den fulde HTML kildekode for Radio klassen
<? <!-- DEBUG: Radio --> <input type="radio" name="Test" id="Radio1" class="baseBody" value="none" tabindex="1" /><!-- DEBUG: Label --> <label for="Radio1" accesskey="T" title="Accelerator key, use (Alt + T)"> <b><span class="baseColorDark">T</span>est</b> (Alt + T) </label><br /> ?>
Her er 'klasse metoderne' for Radio klassen:
Her er 'objekt variable' for Radio klassen: