Sådan benyttes komponenten ViewPlain klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/ViewPlain.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? ViewPlain::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new ViewPlain($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten ViewPlain klassen
Den fulde PHP kildekode for ViewPlain klassen
<?php/** * @package mvc * @see HTML_MVC_VIEW_PATH.'/ViewPlain.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.'/Htmlspecialchars.php');require_once(HTML_MVC_VIEW_PATH.'/ViewCommon.php');/** * Generates the html for a View Plain * <code> * Usage: * $view = new ViewPlain($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); * print $view->getHtml(); * Or * ViewPlain::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); * * Generates a complete View Plain interface * head1, head2, etc * data1, data2, etc * </code> * @package mvc */class ViewPlain extends ViewCommon { /** * Constructor * @param DataReader / array $datareader The Data Reader object OR an array * @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 * @param String $layout The layout to use */ function __construct($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $layout='') { $theText = $text != '' ? $text : ''; // Global table characteristics $theWidth = $width != '' ? $width : LIST_VIEW_WIDTH; $theClass = $class != '' ? $class : LIST_VIEW_CLASS; $theBorder = $border != '' ? $border : LIST_VIEW_BORDER; $theCellPadding = $cellpadding != '' ? $cellpadding : LIST_VIEW_CELLPADDING; $theCellSpacing = $cellspacing != '' ? $cellspacing : LIST_VIEW_CELLSPACING; parent::__construct($datareader, $theText, $theWidth, $theClass, $theBorder, $theCellPadding, $theCellSpacing, $summary, $caption, $layout); } /** * Return the content as an object * @return Object The content as an object */ function newContent() { $object = new Raw(); $numrows = $this->datareader->getNumRows(); $this->text .= $numrows; $html = $this->text."<br />\r\n"; $header = ''; $data = ''; if ($numrows > 0) { $i = 0; foreach($this->datareader->getRows() as $no=>$row) { if ($i === 0) { foreach($row as $key=>$rawvalue) { $value = $this->strip($rawvalue, __FILE__, __LINE__); $header .= ($header != '' ? ',' : '').'"'.$key.'"'; } $html .= "$header\r\n"; $header = ''; } foreach($row as $key=>$rawvalue) { $value = $this->strip($rawvalue, __FILE__, __LINE__); $data .= ($data != '' ? ',' : '').'"'.$value.'"'; } $html .= "$data\r\n"; $data = ''; $i++; } } else { $html .= TEXT_NO_DATA."<br />\r\n"; } // TODO, should be more object $object->add(new Raw($html)); return $object; } /** * Return the html * @return String The html */ function getHtml() { $html = $this->html; $this->add($this->newContent()); // Render it if ($this->getSizeof() > 0) { $html .= $this->getElements(); } //$html .= $this->getTableHeader(); //$html .= $this->getStart(); //$html .= $this->getEnd(); return $html; } /** * Display html * <code> * Usage: * ViewPlain::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); * </code> * @static * @param DataReader / array $datareader The Data Reader object OR an array * @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 * @param String $layout The layout to use */ public static function display($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $layout='') { $html = new ViewPlain($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); $html->addHtml(); }}?>
Den fulde HTML kildekode for ViewPlain klassen
<? <!-- DEBUG: ViewPlain --> 1<br /> "private_phone","contact_person","company_name","address","zip","city","country" "48246030","Finn Rasmussen","HvepseEksperten.dk ApS","Kongens Vænge 79","3400","Hillerød","Denmark" ?>
Her er 'klasse metoderne' for ViewPlain klassen:
Her er 'objekt variable' for ViewPlain klassen: