Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Form  /  Elementfactory   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tl.gif Base tr.gif tl.gif Basic tr.gif tl.gif Dto tr.gif tls.gif     Form  trs.gif tl.gif Language tr.gif tl.gif Layout tr.gif tl.gif Menu tr.gif tl.gif Mvc tr.gif tl.gif Netbank.eksperter.dk tr.gif tl.gif Tab tr.gif tl.gif Table tr.gif tl.gif Util tr.gif
blank.gif
blank.gif
arrow-headline.gif Index
MenuLink  MenuLeft  
Tilbage

Skjul: Navn

ElementFactory.php


Vis: Sample code, tutorial

ElementFactory, Sample code, tutorial

Sådan benyttes komponenten ElementFactory klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

  • <?
    require_once(HTML_PACKAGE_PATH.'/ElementFactory.php');
    ?>

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

  • <?
    ElementFactory
    ::display($param1$param2$param3, ...);
    ?>

eller du kan lave en instance af komponenten og benytte metoderne direkte:

  • <?
    $object 
    = new ElementFactory($param1$param2$param3, ...);
    print 
    $object->getHtml();
    ?>

Skjul: Sådan vises komponenten

ElementFactory, Sådan vises komponenten

Sådan vises komponenten ElementFactory klassen



Vis: PHP source code

ElementFactory, PHP source code

Den fulde PHP kildekode for ElementFactory klassen

<?php
/**
 * @package form
 * @see HTML_FORM_COMPONENT_PATH.'/ElementFactory.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.'/Raw.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/Label.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/Text.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/Readonly.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/Textarea.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/Password.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/Hidden.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/Disabled.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/Checkbox.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/Radio.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/Fileupload.php');
if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
    require_once(
HTML_LANGUAGE_UTIL_PATH.'/Translate.php');
}
if (
defined('HTML_LOG_UTIL_PATH')) {
    require_once(
HTML_LOG_UTIL_PATH.'/Log.php');
}

/**
 * The Element Factory is used to return a complete populated 
 * element object, consisting of a label object and a input object.
 * <code>
 * Usage:
 *   $factory = new ElementFactory();
 *   $element  = $factory->newElement($type, $key, $name, $value, $len, $required, $debug, $class);
 *   print $element->getHtml();
 * Or 
 *   $label  = $factory->newLabel($type, $key, $required;
 *   print $label->getHtml();
 * Or 
 *   $input  = $factory->newInput($type, $name, $value, $len, $debug, $class);
 *   print $input->getHtml();
 * Or 
 *   $element = ElementFactory::newElement($type, $key, $name, $value, $len, $required, $debug, $class);
 *   print $element->getHtml();
 * Or 
 *   $label = ElementFactory::newLabel($type, $key, $required);
 *   print $label->getHtml(); // Use the object
 * Or 
 *   $input = ElementFactory::newInput($type, $name, $value, $len, $debug, $class);
 *   print $input->getHtml();
 * </code>
 * @package form
 */

class ElementFactory {
    
/**
     * Constructor
     */
    
function __construct() {
    }
    
    
/**
     * Return the element for a Label and Input as an object
     * checkbox and radio buttons are also supported
     * @param  String $type     The type to use
     * @param  String $key      The Key to use
     * @param  String $name     The name to use
     * @param  String $value    The value to use
     * @param  String $len      The maxsize to use (OR $onclick if Checkbox)
     * @param  String $required The required text to use, if any
     * @param  String $debug    The debug text to use, if any
     * @param  String $checked  The checked attribute if ticked off for radio/checkbox
     * @param  String $class    The CSS class name to use, if any
     * @param  String $onblur   The onblur event code, if any
     * @return Object The html as an Object 
     */
    
public static function newElement($type$key$name$value$len=''$required=''$debug=''$checked=''$class=''$onblur='') {
        
$object = new Raw();
        if (
$type == 'radio' || $type == 'checkbox') {
            
$object->add(ElementFactory::newInput($type$name$value$len$debug$checked$class));
            
$object->add(ElementFactory::newLabel($type$key$required));
        } else {
            
$object->add(ElementFactory::newLabel($type$key$required));
            
$object->add(ElementFactory::newInput($type$name$value$len$debug''$class$onblur));
        }
        return 
$object;
    }

    
/**
     * Return the Input element as an object
     * @param  String $type     The type to use
     * @param  String $name     The name to use
     * @param  String $value    The value to use
     * @param  String $len      The maxsize to use (OR $onclick if a Checkbox)
     * @param  String $debug    The debug text to use, if any
     * @param  String $checked  The checked attribute if ticked off for radio/checkbox
     * @param  String $class    The CSS class name to use, if any
     * @param  String $onblur   The onblur event code, if any
     * @return Object The html as an Object 
     */
    
public static function newInput($type$name$value$len=''$debug=''$checked=''$class=''$onblur='') {
        
$object = new Raw();
        
$title $debug;
        
$element ucfirst($type); // The element class name
        
switch ($type) {
            case 
'hidden':
                
$title  $debug;
                
$object = new $element($name$value$title);
                break;
            case 
'file':
                if (
$element=='') {
                    
$element .= 'upload';
                } 
                
// Intentionally fall through
            
case 'text':
            case 
'password':
            case 
'readonly':
            case 
'disabled':
                
$size      "";
                
$maxlength $len;
                
$disabled  "";
                
$readonly  "";
                
$onclick   "";
                
$tabindex  "";
                
$accesskey "";
                
$onfocus   "";
                
$object = new $element($name$value$class$size$maxlength$disabled$readonly$onclick$title$tabindex$accesskey$onfocus$onblur);
                break;
            case 
'checkbox':
            case 
'radio':
                
$disabled  "";
                
$onclick   $len
                
$tabindex  "";
                
$accesskey "";
                
$object = new $element($name$value$class$checked$disabled$onclick$title$tabindex$accesskey);
                break;
            case 
'textarea'
                
// Change to new type of element
                
$text      $value;
                
$rows      "";
                
$cols      "";
                
$tabindex  "";
                
$accesskey "";
                
$wrap      "";
                
$object = new $element($name$text$rows$cols$class$title$tabindex$accesskey$wrap);
                break;
            default:
                die(
'File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n"."ElementFactory::newInput(type,..), unknown type, found type=".$type);
                break;
        }
        return 
$object;
    }

    
/**
     * Return the Label element as an object
     * @param  String $type     The type to use
     * @param  String $key      The Key to use
     * @param  String $required The required text to use, if any
     * @return Object The html as an Object 
     */
    
public static function newLabel($type$key$required='') {
        
$object = new Raw();
        
/**
         * Ignore the accesskey and 'for=' for Label when type is readonly, disabled or hidden
         */
        
$for       '';
        
$accesskey '';
        switch (
$type) {
            case 
'readonly':
            case 
'disabled':
            case 
'hidden':
                
$for false;
                
$accesskey false;
                break;
            default:
                break;
        }
        if (
$type !== 'hidden') {
            
$text $key;
            if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
                
$text Translate::sql($key);
            }
            
$object = new Label($text.$required$for$accesskey);
        }
        return 
$object;
    }
    
    
/**
     * Get the html code
     * @return String The html code
     */
    
function getHtml() {
        
$element ElementFactory::newElement('checkbox''Test''Test''Test');
        return 
$element->getHtml();
    }
}
?>

Vis: HTML source code

ElementFactory, HTML source code

Den fulde HTML kildekode for ElementFactory klassen

<?
<!-- DEBUGCheckbox -->
<
input type="checkbox" name="Test" id="Checkbox1" class="baseBody" value="Test" tabindex="1" />

<!-- 
DEBUGLabel -->
<
label for="Checkbox1" accesskey="T" title="Accelerator key, use (Alt + T)">
    <
b><span class="baseColorDark">T</span>est</b>&nbsp; (Alt T) </label><br />


?>

Vis: Class methods

ElementFactory, Class methods

Her er 'klasse metoderne' for ElementFactory klassen:

  • __construct
  • newElement
  • newInput
  • newLabel
  • getHtml

Vis: Object vars

ElementFactory, Object vars

Her er 'objekt variable' for ElementFactory klassen:


MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


 
blank.gif
MenuBottom 
triangle.gif Copyright @ 1999-2010 www.Finn-Rasmussen.com Powered by myPHP Version (5.3.3-7+squeeze3) 1.11
blank.gif