ViewSimple
ViewSimple Du er her: /  Forsiden  /  Kildekoden  /  Mvc  /  Viewsimple   Login nu   Login
ViewSimple
ViewSimple
ViewSimple Basic ViewSimple ViewSimple Base ViewSimple ViewSimple Component ViewSimple ViewSimple Db ViewSimple ViewSimple Dto ViewSimple ViewSimple Form ViewSimple ViewSimple Form-elements ViewSimple ViewSimple Jquery ViewSimple ViewSimple Layout ViewSimple ViewSimple Menu ViewSimple ViewSimple Menu-fisheye ViewSimple ViewSimple Mvc  ViewSimple ViewSimple Tab ViewSimple ViewSimple Table ViewSimple ViewSimple Template ViewSimple ViewSimple Util ViewSimple
ViewSimple
ViewSimple
ViewSimple Index
 
Tilbage

Navn : ViewSimple.php


Sample code, tutorial

Sådan benyttes komponenten ViewSimple klassen

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

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

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

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

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

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

Parent html

Sådan vises komponenten ViewSimple klassen

private_phone: 48246030
Finn Rasmussen 
HvepseEksperten.dk ApS 
Kongens Vænge 79 
3400&nbsp;Hillerød 
Denmark 

PHP source code

Den fulde PHP kildekode for ViewSimple klassen

<?
/**
* @package mvc
* @see HTML_MVC_VIEW_PATH.'/ViewSimple.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_BASE_UTIL_PATH.'/Htmlspecialchars.php');
require_once(
HTML_MVC_VIEW_PATH.'/ViewCommon.php');
require_once(
HTML_BASE_UTIL_PATH.'/Hr.php');
require_once(
HTML_BASE_UTIL_PATH.'/EmailLink.php');
require_once(
HTML_BASE_UTIL_PATH.'/Lookup.php');
if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
    require_once(
HTML_LANGUAGE_UTIL_PATH.'/Translate.php');
}

/**
* Generates the html for a View Simple like a business card look-a-like
* <code>
* Usage:
*   $view = new ViewSimple($datareader,$text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
*   print $view->getHtml();
* Or
*   ViewSimple::display($datareader,$text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
*
* Generates a complete View Simple interface
* +--------+
* | Header |
* +--------+
* | data1  |
* +--------+
* | data2  |
* +--------+
* </code>
* @package mvc
*/

class ViewSimple extends ViewCommon {
    
/**
     * Constructor
     * @param DataReader $datareader The Data Reader object
     * @param String $text    The text header for the table
     * @param String $width   The Width for the table
     * @param String $class   The Class
     * @param String $border  The Border
     * @param String $cellpadding The CellSpacing
     * @param String $cellspacing The CellPadding
     * @param String $summary The Summary
     * @param String $caption The Caption
     */
    
function ViewSimple($datareader,$text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
        
$theText        = $text!=''?$text:'';

        
// Global table characteristics
        
$theWidth       = $width!=''?$width:SIMPLE_VIEW_WIDTH;
        
$theClass       = $class!=''?$class:SIMPLE_VIEW_CLASS;
        
$theBorder      = $border!=''?$border:SIMPLE_VIEW_BORDER;
        
$theCellPadding = $cellpadding!=''?$cellpadding:SIMPLE_VIEW_CELLPADDING;
        
$theCellSpacing = $cellspacing!=''?$cellspacing:SIMPLE_VIEW_CELLSPACING;
        
$this->ViewCommon($datareader,$theText,$theWidth,$theClass,$theBorder,$theCellPadding,$theCellSpacing,$summary,$caption);
    }

    
/**
     * Return the column header data as an object
     * @param  String $key The key to use
     * @return Object The html as an object
     */
    
function newHeader($key) {
        
$text = $key;
        if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
            
$text = Translate::sql($key,TRANSLATE_QUERY);
        }
        return new
Raw($text."&nbsp;");
    }
    
    
/**
     * Return the column data as an object
     * @param  String $key     The key to use
     * @param  String $value   The value to use
     * @param  String $cssData The CSS Data to use
     * @param  boolean $isSingleColumn The column data is a single column. Default more columns
     * @return Object The html as an object
     */
    
function newColumn($key, $value, $cssData, $isSingleColumn=false) {
        
$object = new Raw();
        
$text = '';
        
$value = Htmlspecialchars::encode($value);
        switch (
$key) {
            case
SELECT_EMAIL:
                
$text = $key;
                if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
                    
$text = Translate::sql($key,TRANSLATE_QUERY);
                }
                
$object->add(new EmailLink($isSingleColumn?"$text:&nbsp;$value":'',$value,$cssData));
                break;
            case
SELECT_PRIVATE_PHONE:
            case
SELECT_BUSINESS_PHONE:
            case
SELECT_MOBILE_PHONE:
                
$text = $key;
                if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
                    
$text = Translate::sql($key,TRANSLATE_QUERY);
                }
                
$object = new Raw(($isSingleColumn?"$text:&nbsp;":'').$value);
                
//$object->add(new Lookup($value));
                
break;
            default:
// Use as is
                
$object = new Raw("$value&nbsp;");
                break;
        }
        return
$object;
    }
    
    
/**
     * Return the row data as html
     * <tr><td>header 1</td><td>data 1</td></tr> ...
     * @param array   $row The rows to loop
     * @param String  $cssHeader The CSS Header to use
     * @param String  $cssData   The CSS Data to use
     * @param boolean $isSingleColumn This is a single column if true. Default is false
     * @return Object The html as an object
     */
    
function newRow($row,$cssHeader,$cssData,$isSingleColumn=false) {
        
$object = new Raw();
        if (
count($row)>0) {
            
$zip = '';
            foreach(
$row as $key=>$rawvalue) {
                
$value = Htmlspecialchars::encode($rawvalue);
                switch (
$key) {
                    case
SELECT_ZIP:
                        
$zip = $value;
                        break;
                    case
SELECT_CITY:
                        
$value = $zip.'&nbsp;'.$value;
                        
// Intentionally fall through
                    
default:
                        if (
$value != '') {
                            
$tr = new Tr();
                            if (
$isSingleColumn) {
                                
// Ignore key column
                            
} else {
                                
$td = new Th($cssHeader);
                                
$td->add($this->newHeader($key));
                                
$tr->add($td);
                            }
                            
$td = new Td($cssData);
                            
$td->add($this->newColumn($key, $value, $cssData, $isSingleColumn));
                            
$tr->add($td);
                            
$object->add($tr);
                        }
                        break;
                }
            }
        }
        return
$object;
    }

    
/**
     * Return the content as an object
     * @return Object The content as an object
     */
    
function newContent() {
        
$object = new Raw();
        
$numrows = $this->datareader->getNumRows();
        if (
$numrows>0) {
            if (
$numrows>1) {
                
$this->text .= $this->text!=''?" ($numrows)":'';
                
$td = new Td();
                
$td->add(new Raw("TODO More than one ..."));
                
$object->add($td);
            }
            
$isSingleColumn = true; // Single Column, like a business card
            
$count = 0;
            foreach(
$this->datareader->getRows() as $no=>$row) {
                
$rowcolor = Rowcolor::get($count++);
                
$object->add($this->newRow($row,CSS_COLOR_HEADER,$rowcolor,$isSingleColumn));
            }
        } else {
            
$object = new Tr();
            
$object->add($this->newTextRow(TEXT_NO_DATA, LINK_BACK));
        }
        return
$object;
    }

    
/**
     * Return the html
     * @return String The html
     */
    
function getHtml() {
        
$html = $this->html;
        
$this->add($this->newContent());
        
// Render it
        
if ($this->text != '') {
            
$html .= $this->getTableHeader();
        }
        
$html .= $this->getStart();
        
$html .= $this->getEnd();
        return
$html;
    }

    
/**
     * Display html
     * <code>
     * Usage:
     *    ViewSimple::display($datareader,$text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
     * </code>
     * @static
     * @param DataReader $datareader The Data Reader object
     * @param String $text    The text header for the table
     * @param String $width   The width of the table
     * @param String $class   The class of the table
     * @param String $border  The border of the table
     * @param String $cellpadding The CellSpacing
     * @param String $cellspacing The CellPadding
     * @param String $summary The Summary
     * @param String $caption The Caption
     */
    
function display($datareader,$text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
        
$html = new ViewSimple($datareader,$text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
        
$html->addHtml();
    }
}
?>

HTML source code

Den fulde HTML kildekode for ViewSimple klassen

<?

<table width="323" class="CSS_SIMPLE_VIEW baseBorder" border="0" cellpadding="2" cellspacing="0">
<
tr>
    <
td class="baseColorDark" valign="top">private_phone:&nbsp;48246030</td>
</
tr>

<
tr>
    <
td class="baseColorDark" valign="top">Finn Rasmussen&nbsp;</td>
</
tr>

<
tr>
    <
td class="baseColorDark" valign="top">HvepseEksperten.dk ApS&nbsp;</td>
</
tr>

<
tr>
    <
td class="baseColorDark" valign="top">Kongens Vænge 79&nbsp;</td>
</
tr>

<
tr>
    <
td class="baseColorDark" valign="top">3400&amp;nbsp;Hillerød&nbsp;</td>
</
tr>

<
tr>
    <
td class="baseColorDark" valign="top">Denmark&nbsp;</td>
</
tr>

<
tr>
    <
td class="baseColorDark" valign="top">private_phone:&nbsp;48246030</td>
</
tr>

<
tr>
    <
td class="baseColorDark" valign="top">Finn Rasmussen&nbsp;</td>
</
tr>

<
tr>
    <
td class="baseColorDark" valign="top">HvepseEksperten.dk ApS&nbsp;</td>
</
tr>

<
tr>
    <
td class="baseColorDark" valign="top">Kongens Vænge 79&nbsp;</td>
</
tr>

<
tr>
    <
td class="baseColorDark" valign="top">3400&amp;nbsp;Hillerød&nbsp;</td>
</
tr>

<
tr>
    <
td class="baseColorDark" valign="top">Denmark&nbsp;</td>
</
tr>

</
table>

?>

Class methods

Her er 'klasse metoderne' for ViewSimple klassen:

  • viewsimple
  • newheader
  • newcolumn
  • newrow
  • newcontent
  • gethtml
  • display
  • object
  • getclassname
  • getmsg
  • addhtml
  • tostring
  • getcachefilename
  • save
  • content
  • stop
  • html
  • setobject
  • set
  • get
  • getattribute
  • gettag
  • add
  • getsizeof
  • getelement
  • getelements
  • gettoogle
  • getmaximize
  • getminimize
  • newtriangle
  • showsource
  • table
  • newtextrow
  • gettableheader
  • getstart
  • getend
  • start
  • end
  • viewcommon
  • newhiddens
  • newbuttons
  • newelement

Object vars

Her er 'objekt variable' for ViewSimple klassen:

  • html =>
  • sql =>
  • elements => Array
  • sizeof => 2
  • text =>
  • width => 323
  • class => CSS_SIMPLE_VIEW baseBorder
  • border => 0
  • cellpadding => 2
  • cellspacing => 0
  • summary =>
  • caption =>
  • datareader => Object
  • id =>
  • subtotal =>

DataReader.php

Her er felterne i DataReader for ViewSimple klassen:

  0   














ViewSimple

Vis denne side på danmark

Vis denne side på Germany

Vis denne side på England

Vis denne side på France

Vis denne side på Italy

Vis denne side på Norge

Vis denne side på Sverige

Vis denne side på USA


 
ViewSimple
ViewSimple
ViewSimple