Sådan benyttes komponenten ViewDetail klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/ViewDetail.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? ViewDetail::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new ViewDetail($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten ViewDetail klassen
Den fulde PHP kildekode for ViewDetail klassen
<?php/** * @package mvc * @see HTML_MVC_VIEW_PATH.'/ViewDetail.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_MVC_VIEW_PATH.'/ViewSimple.php');/** * Generates the html for a View Detail * <code> * Usage: * $rows = array( array("head1"=>"data1", "head2"=>"data2"), ); * $header = ''; // The header meta data * $default = ''; // The default meta data array * $limit = ''; // The limit to use for the array * $sort = true; * $datareader = DataReaderFactory::newDataReader($rows, $header, $default, $limit, $sort); * $text = "Text header"; * $width = "200px"; * $class = ""; * $border = "0"; * $cellpadding = "2"; * $cellspacing = "0"; * $view = new ViewDetail($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); * print $view->getHtml(); * Or * ViewDetail::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); * * Generates a complete View Detail interface * +---------------+ * | Text header | * +---------------- * | head1 | data1 | * +--------------- * | head2 | data2 | * +---------------+ * </code> * @package mvc */class ViewDetail extends ViewSimple { /** * 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 : 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; 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(); if ($numrows > 0) { if ($numrows > 1) { $tr = new Tr(); $this->text .= $this->text != '' ? " ($numrows)" : ''; $td = new Td('','','',"TODO More than one ($numrows) ...<br />\r\n"); $tr->add($td); $link = new Links(LINK_BACK); $td = new Td('','','', $link); $tr->add($td); $object->add($tr); } $count = 0; foreach($this->datareader->getRows() as $no=>$row) { $rowcolor = Rowcolor::get($count++); if ($count > 1) { $tr = new Tr(); $valign = ""; $colspan = 2; $text = new Hr(); $td = new Td($rowcolor, $valign, $colspan, $text); $tr->add($td); $object->add($tr); } $cssHeader = ""; $cssData = $rowcolor; $isSingleColumn = false; $object->add($this->newRow($row, $cssHeader, $cssData, $isSingleColumn)); } } else { $object->add($this->newTextRow(TEXT_NO_DATA, LINK_BACK)); } return $object; } /** * Display html * <code> * Usage: * ViewDetail::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 ViewDetail($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); $html->addHtml(); }}?>
Den fulde HTML kildekode for ViewDetail klassen
<? <!-- DEBUG: ViewDetail --> <table id="ViewDetailId" width="400" class="simpleView baseBorder" border="0" cellpadding="2" cellspacing="0"> <tr> <th class="baseColorDark" valign="top">Privat telefon </th> <td class="baseColorDark" valign="top">48246030 </td> </tr> <tr> <th class="baseColorLight" valign="top">Kontakt person </th> <td class="baseColorLight" valign="top">Finn Rasmussen </td> </tr> <tr> <th class="baseColorDark" valign="top">Firmanavn </th> <td class="baseColorDark" valign="top">HvepseEksperten.dk ApS </td> </tr> <tr> <th class="baseColorLight" valign="top">Adresse </th> <td class="baseColorLight" valign="top">Kongens Vænge 79 </td> </tr> <tr> <th class="baseColorLight" valign="top">By </th> <td class="baseColorLight" valign="top">3400 Hillerød </td> </tr> <tr> <th class="baseColorDark" valign="top">Land </th> <td class="baseColorDark" valign="top">Denmark </td> </tr> </table> ?>
Her er 'klasse metoderne' for ViewDetail klassen:
Her er 'objekt variable' for ViewDetail klassen: