Sådan benyttes komponenten Hiddens klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/Hiddens.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? Hiddens::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new Hiddens($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten Hiddens klassen
Den fulde PHP kildekode for Hiddens klassen
<?php/** * @package form * @filesource * @see HTML_FORM_COMPONENT_PATH.'/Hiddens.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_FORM_COMPONENT_PATH.'/Hidden.php');require_once(HTML_UTIL_COMPONENT_PATH.'/Params.php');/** * Create the hidden fields used in a form * <code> * Usage: * $keyValue = array(); * $title = "title on the command element"; * $debug = "debug info for the command element"; * * $hiddens = new Hiddens($keyValue, $title, $debug); * print $hiddens->getHtml(); * Or * Hiddens::display($keyValue, $title, $debug); * </code> * @package form */class Hiddens extends Html { /** * @var array $keyValue Optionally array of key value pairs, or empty */ protected $keyValue = array(); /** * @var String $title The title for the next command to execute */ protected $title = ''; /** * @var String $debug The debug text to use, if any */ protected $debug = ''; /** * Constructor * @param array $keyValue Optionally array of key value pairs, or empty * @param String $title The title for the next command to execute * @param String $debug The debug text to use, if any */ function __construct(array $keyValue=array(), $title='', $debug='') { parent::__construct(); $this->keyValue = $keyValue; $this->title = $title; $this->debug = $debug; } /** * Get the html for the specified hidden field * @param String $name The name of the request key * @param String $const The const string of the request key * @param array $keyValue Optionally array of key value pairs, or empty * @param array $vars The request array send as a GET or POST * @param String $title The title for the hidden field * @return String The html */ function getHidden($name, $const, $keyValue, $vars, $title='') { $html = ''; if (defined($name) && !empty($vars[$const])) { if (!array_key_exists($const, $keyValue)) { if (defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) { $title = $title != '' ? $title." $name" : $name; } $filename = __FILE__; $lineno = __LINE__; if (Params::validate($const, $vars[$const], $filename, $lineno)) { $hidden = new Hidden($const, $vars[$const], $title); $html .= $hidden->getHtml(); } else { if (defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) { $html = "<!-- DEBUG: Hiddens->getHidden() Params::validate($name) failed -->\r\n"; } } } else { if (defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) { $html = "<!-- DEBUG: $name already defined -->\r\n"; } } } else { if (defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) { //$html = "<!-- DEBUG: $name -->\r\n"; } } return $html; } /** * Get the html for all the hidden fields * If the hidden element is REQUEST_COMMAND, then add title and optionally debug info * @see Params * @param array $vars The request array send as a GET or POST * @return String The html */ function getHiddens($vars) { $html = ''; $keyValue = $this->keyValue; foreach($keyValue as $key=>$value) { if ($value != '') { $filename = __FILE__; $lineno = __LINE__; if (Params::validate($key, $value, $filename, $lineno)) { $title = ""; if ($key === REQUEST_COMMAND) { $title = $this->title; if ($this->debug !== '') { $title .= ' ('.$this->debug.')'; } } $hidden = new Hidden($key, $value, $title); $html .= $hidden->getHtml(); } else { if (defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) { $html = "<!-- DEBUG: Hiddens->getHiddens() Params::validate($key) failed -->\r\n"; } } } } // REQUEST_COMMAND is Added in the form where the Buttons are defined etc. //$html .= $this->getHidden('REQUEST_COMMAND',REQUEST_COMMAND, $keyValue, $vars, $this->title); $html .= $this->getHidden('REQUEST_TABLE',@REQUEST_TABLE, $keyValue, $vars, $this->title); $html .= $this->getHidden('REQUEST_NEXT',REQUEST_NEXT, $keyValue, $vars, $this->title); // Where did the user come from $html .= $this->getHidden('REQUEST_REFERER',REQUEST_REFERER, $keyValue, $vars, $this->title); // CMS $html .= $this->getHidden('REQUEST_PAGE_DOMAINNAME',REQUEST_PAGE_DOMAINNAME, $keyValue, $vars); $html .= $this->getHidden('REQUEST_BASE_PACKAGE_TEST',REQUEST_BASE_PACKAGE_TEST, $keyValue, $vars); $html .= $this->getHidden('REQUEST_ORDER_BY_NAME',@REQUEST_ORDER_BY_NAME, $keyValue, $vars); $html .= $this->getHidden('REQUEST_SORT_BY_NAME',@REQUEST_SORT_BY_NAME, $keyValue, $vars); if (defined('REQUEST_LANGUAGE')) { $html .= $this->getHidden('REQUEST_LANGUAGE',REQUEST_LANGUAGE, $keyValue, $vars); } $html .= $this->getHidden('REQUEST_SID',REQUEST_SID, $keyValue, $vars); // ViewSearchColumns, problems with default init value //$html .= $this->getHidden('REQUEST_VIEW_COLUMN_NAME',REQUEST_VIEW_COLUMN_NAME, $keyValue, $vars); $html .= $this->getHidden('REQUEST_LIMIT_NAME_SKIP',@REQUEST_LIMIT_NAME_SKIP, $keyValue, $vars); $html .= $this->getHidden('REQUEST_LIMIT_NAME_SHOW',@REQUEST_LIMIT_NAME_SHOW, $keyValue, $vars); return $html; } /** * Returns the html for all the hidden fields for a form * @return String The html */ function getHiddenFields() { return $this->getHiddens($_SERVER['REQUEST_METHOD'] === REQUEST_METHOD_POST ? $_POST : $_GET); } /** * Get the complete html for the hidden fields in a form * @return String The html */ function getHtml() { $html = $this->html; if (defined('DEBUG_LEVEL_SHOW_INFO') && (DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) && $this->debug != '') { $html .= "<!-- ".$this->getClassName()." ".$this->debug." -->\r\n"; } $html .= $this->getHiddenFields(); $html .= $this->getElements(); // Could be other hidden fields return $html; } /** * Display html * <code> * Usage: * Hiddens::display($keyValue, $title, $debug); * </code> * @static * @param array $keyValue Optionally array of key value pairs, or empty * @param String $title The title for the next command to execute * @param String $debug The debug text, if any */ public static function display(array $keyValue=array(), $title='', $debug='') { $html = new Hiddens($keyValue, $title, $debug); $html->addHtml(); }}?>
Den fulde HTML kildekode for Hiddens klassen
<? <!-- DEBUG: Hiddens --> ?>
Her er 'klasse metoderne' for Hiddens klassen:
Her er 'objekt variable' for Hiddens klassen: