blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Form-elements  /  Controlfactory   Login nu   Login
blank.gif
 ««« Se kilde koden
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 : ControlFactory.php


Sample code, tutorial

Sådan benyttes komponenten ControlFactory klassen

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

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

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

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

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

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

Parent html

Sådan vises komponenten ControlFactory klassen

Der er ikke fundet noget

PHP source code

Den fulde PHP kildekode for ControlFactory klassen

<?
/**
* @package form-element
* @see HTML_FORM_ELEMENTS_COMPONENT_PATH.'/ControlFactory.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
*/
require_once(HTML_BASIC_UTIL_PATH.'/Singleton.php');
require_once(
HTML_FORM_ELEMENTS_PAGE_PATH.'/ControlEmail.php');
require_once(
HTML_FORM_ELEMENTS_PAGE_PATH.'/ControlPassword.php');
require_once(
HTML_FORM_ELEMENTS_PAGE_PATH.'/ControlFileupload.php');
require_once(
HTML_FORM_ELEMENTS_PAGE_PATH.'/ControlAccept.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/ElementFactory.php');
require_once(
HTML_LANGUAGE_UTIL_PATH.'/Translate.php');
if (
defined('HTML_LOG_UTIL_PATH')) {
    require_once(
HTML_LOG_UTIL_PATH.'/Log.php');
}

/**
* The Control Factory is used to return a complete populated
* element object, consisting of a label object and a input object.
* The element is returned as a singleton.
* <code>
* Usage:
*   $factory = new ControlFactory();
*   $element  = $factory->getInstance($label,$name,$classname,$useLabel);
*   print $element->getHtml(); // Use the object
* Or
*   $element  = ControlFactory::getInstance($label,$name,$classname,$useLabel);
*   print $element->getHtml(); // Use the object
* </code>
* @package form-element
*/

class ControlFactory {
    
/**
     * Constructor
     */
    
function ControlFactory() {
    }
    
    
/**
     * Return the control as an object
     * @static
     * @param  Label      $label     The Label object
     * @param  Text field $control   The Control object
     * @param  String     $classname The class name of the control
     * @return Object The html as an Object
     */
    
function getSingleton($label,$control,$classname) {
        
$element = & Singleton::getInstance($classname);
        
$element->set(CLASS_VAR_LABEL,$label);
         
$element->set(CLASS_VAR_CONTROL,$control);
        return
$element;
    }

    
/**
     * Return the control as an singleton instance object
     * @static
     * @param  Label   $label     The Label object
     * @param  String  $name      The name of the control
     * @param  String  $classname The class name of the control
     * @param  boolean $useLabel  The Control has a label (true) or not (false)
     * @return Object The html as an Object
     */
    
function getInstance($label,$name,$classname,$useLabel=true) {
        
$required = ''; // Debug
        
$type = 'UNKNOWN';
        switch (
$classname) {
            case
CLASS_NAME_CONTROL_EMAIL:
                
$type = 'text';
                break;
            case
CLASS_NAME_CONTROL_PASSWORD:
                
$type = 'password';
                break;
            case
CLASS_NAME_CONTROL_FILEUPLOAD:
                
$type = 'fileupload';
                break;
            case
CLASS_NAME_CONTROL_ACCEPT:
                
$type = 'checkbox';
                break;
            default:
                die(
'File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n"."ControlFactory::getInstance(type,..), unknown classname, found classname=".$classname);
                break;
        }
        
        
/**
         * Checkbox and Label objects MUST be constructed in reverse order
         * because of the automatic id and label association
         * @see Element
         */
        
if ($useLabel && $type != 'checkbox') {
            
// Must be instanciated BEFORE the text field
            
$label = ElementFactory::newLabel($type,$label,$required);
        }
        
$value = '';
        
$len   = '';
        
$debug = '';
        
$control = ElementFactory::newInput($type,$name,$value,$len,$debug);
        if (!
$useLabel) {
            
$control->setId('');
        }
        
/**
         * Checkbox and Label objects MUST be constructed in reverse order
         * because of the automatic id and label association
         * @see Element
         */
        
if ($useLabel && $type == 'checkbox') {
            
// Must be instanciated BEFORE the text field
            
$label = ElementFactory::newLabel($type,$label,$required);
        }
        return
ControlFactory::getSingleton($label,$control,$classname);
    }
}
?>

HTML source code

Den fulde HTML kildekode for ControlFactory klassen

Der er ikke fundet noget

Class methods

Her er 'klasse metoderne' for ControlFactory klassen:

  • controlfactory
  • getsingleton
  • getinstance

Object vars

Her er 'objekt variable' for ControlFactory klassen:


 
triangle.gif

danmark

Germany

England

France

Italy

Norge

Sverige

USA


 
blank.gif