Sådan benyttes komponenten Request klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/Request.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? Request::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new Request($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten Request klassen
Request->getHtml(), Der er ikke fundet noget
Den fulde PHP kildekode for Request klassen
<?php/** * @package util * @see HTML_UTIL_COMPONENT_PATH.'/Request.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 */ if (defined('HTML_LANGUAGE_UTIL_PATH')) { require_once(HTML_LANGUAGE_UTIL_PATH.'/Locale.php'); }/** * The Request object. * Return the Request information from a GET/POST request * or use the $default value, if supplied * <code> * Usage: * $html = new Request(); * print $html->getHtml(); * print $html->get($key, $default); * Or * print Request::display(); * Or * print Request::get($key, $default); * </code> * @package util */class Request { /** * Constructor */ function __construct() { } /** * Returns the request info as html * Note: Intentionally removed the key/value pairs when in the public area * @return String The html */ function getHtml() { $html = ''; $count = count($_GET) + count($_POST); if ($count > 0) { $no = 1; $html .= '<table border="1" class="Border" cellpadding="1" cellspacing="0" width="450">'."\r\n"; foreach ($_GET as $key=>$value) { //$html .= ' <tr><td valign="top">'.$key.'</td><td valign="top">'.$value.' </td></tr>'."\r\n"; $html .= ' <tr><td valign="top">Key'.$no.'</td><td valign="top">Value'.$no++.'</td></tr>'."\r\n"; } foreach ($_POST as $key=>$value) { //$html .= ' <tr><td valign="top">'.$key.'</td><td valign="top">'.$value.' </td></tr>'."\r\n"; $html .= ' <tr><td valign="top">Key'.$no.'</td><td valign="top">Value'.$no++.'</td></tr>'."\r\n"; } $html .= "</table >\r\n"; } else { $html .= '<p>Request->getHtml(), '; if (defined('TEXT_NO_DATA')) { $html .= TEXT_NO_DATA; } else { $html .= REQUEST_TEXT_NO_DATA; } $html .= "</p>\r\n"; } return $html; } /** * Display html * Add the html to the Buffer object * <code> * Usage: * Request::display(); * </code> * @static */ public static function display() { $html = new Request(); $html->addHtml($html->getHtml()); } /** * Normally implemented in Object, add to Buffer object * NOTE: This method expect that a Buffer object is instanciated * @param String $html The html to add */ function addHtml($html) { print $html; } /** * Return the request parameters for the GET/POST request * <code> * Usage: * Request::method($method); * </code> * @static * @param String $method Request parameters from GET/POST * @return String The key/value pair of the requested key */ function method($method) { die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".'Request::params() NOT TESTED'); $html = ''; foreach($method as $key=>$value) { switch ($key) { case REQUEST_LANGUAGE: case @REQUEST_TABLE: case REQUEST_ID: case REQUEST_NAME: case REQUEST_SID: case REQUEST_TAB: case REQUEST_PROJECT: case REQUEST_PAGE: if ($value != '') { $html .= ($html != '' ? '&' : '').$key.'='.$value; } break; case REQUEST_COMMAND: // Intentionally ignore break; default: // Ignore other request params break; } } return $html; } /** * Return the request parameters used for a link * <code> * Usage: * Request::params($param); * </code> * @static * @param String $param Existing parameter string. I.e. 'AB=1 & XY=2' * @return String The key/value pair of the requested key */ public static function params($param='') { die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".'Request::params() NOT TESTED'); $html = ''; if ($html=='') { $html .= Request::method($_GET); } if ($html=='') { $html .= Request::method($_POST); } if ($param != '') { $html .= ($html != '' ? '&' : '').$param; } if ($html != '') { $html .= '?'; } return $html; } /** * Get the request parameter specified by the $key. * If no key is found, use $default value, if specified * <code> * Usage: * $key = REQUEST_TAB_SHOW; * $default = TAB_SHOW_MENU_TAB; * $file = __FILE__; * $line = __LINE__; * $validate = true; * * $request = Request::get($key, $default, $file, $line, $validate); * </code> * @static * @param String $key The Request param key to use from the get/post request * @param String $default The default value to use, if no key/value found * @param String $file The filename of the calling file * @param String $line The line number in the calling file * @param boolean $validate The request parameters must be validated, if TRUE * @return String The value of the requested key */ public static function get($key, $default='', $file='', $line='', $validate=false) { $value = ''; if ($value=='' && isset($_GET[$key]) && $_GET[$key] != '') { $value = $_GET[$key]; } if ($value=='' && isset($_POST[$key]) && $_POST[$key] != '') { $value = $_POST[$key]; } if ($value == '') { $value = $default; } /** * If validate is true, then check for a valid key/value pair * If an illegal value is found, then return "" */ if ($validate) { $filename = $file != '' ? $file : __FILE__; $lineno = $line != '' ? $line : __LINE__; if ($value != '' && !Params::validate($key, $value, $filename, $lineno)) { $value = ""; } } return $value; } /** * Get the locale for the request * If no locale is found return null * <code> * Usage: * $locale = Request::locale(); * print $locale->getLanguage(); * print $locale->getCountry(); * </code> * @static * @param String $language The Language * @param String $country The Country * @return Locale The locale object for the request or null */ public static function locale($language='', $country='') { $locale = null; if (defined('HTML_LANGUAGE_UTIL_PATH')) { $locale = new Locale(); } else { die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".'Request::locale() requires the Language package. Unable to use HTML_LANGUAGE_UTIL_PATH/Locale.php'); } return $locale; } /** * Get all the locales for the request * If no locales are found return empty array * <code> * Usage: * $locales = Request::locales(); * foreach($locales as $locale) { * print $locale->getLanguage(); * print $locale->getCountry(); * } * </code> * @static * @return array of Locale. The array of locale object for the request or empty */ public static function locales() { $locale = array(); if (defined('HTML_LANGUAGE_UTIL_PATH')) { foreach($GLOBALS[DEFINE_COUNTRY] as $key=>$value) { $locale[] = new Locale($key, $value); } } else { die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".'Request::locales() requires the Language package. Unable to use HTML_LANGUAGE_UTIL_PATH/Locale.php'); } return $locale; }}?>
Den fulde HTML kildekode for Request klassen
<? <p>Request->getHtml(), Der er ikke fundet noget</p> ?>
Her er 'klasse metoderne' for Request klassen:
Her er 'objekt variable' for Request klassen: