blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Util  /  Request   Login nu   Login
blank.gif
blank.gif
triangle.gif Basic Base Component Db Dto Form Form-elements Jquery Layout Menu Menu-fisheye Mvc Tab Table Template Util 
blank.gif
blank.gif
 
arrow-headline.gif Index
 
  Tilbage

Navn : Request.php


Sample code, tutorial

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();
    ?>

Parent html

Sådan vises komponenten Request klassen

Request->getHtml(), Der er ikke fundet noget


PHP source code

Den fulde PHP kildekode for Request klassen

<?
/**
* @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.10
* @since 22-feb-2007
*/

/**
* 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 Request() {
    }
    
    
/**
     * 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.'&nbsp;</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.'&nbsp;</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
     */
    
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!=''?'&amp;':'').$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
     */
    
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!=''?'&amp;':'').$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:
     *    Request::get($key,$default);
     * </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
     * @return String The value of the requested key
     */
    
function get($key,$default='') {
        
$value = '';
        if (
$value=='' && isset($_GET[$key]) && $_GET[$key]!='') {
            
$value = $_GET[$key];
        }
        if (
$value=='' && isset($_POST[$key]) && $_POST[$key]!='') {
            
$value = $_POST[$key];
        }
        
// Validate if a valid key/value pair
//        if ($value!='' && !Request::validate($key,$value)) {
//            $value = '';
//        }
        
if ($value=='') {
            
$value = $default;
        }
        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
     */
    
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
     */
    
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;
    }
}
?>

HTML source code

Den fulde HTML kildekode for Request klassen

<?
<p>Request->getHtml(), Der er ikke fundet noget</p>

?>

Class methods

Her er 'klasse metoderne' for Request klassen:

  • request
  • gethtml
  • display
  • addhtml
  • method
  • params
  • get
  • locale
  • locales

Object vars

Her er 'objekt variable' for Request klassen:


 
triangle.gif

danmark

Germany

England

France

Italy

Norge

Sverige

USA


 
blank.gif
blank.gif
blank.gif