Sådan benyttes komponenten ViewBasket klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/ViewBasket.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? ViewBasket::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new ViewBasket($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten ViewBasket klassen
Den fulde PHP kildekode for ViewBasket klassen
<?php/** * @package db-basket * @see HTML_DB_BASKET_VIEW_PATH.'/ViewBasket.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.'/ViewList.php');if (defined('HTML_UTIL_COMPONENT_PATH')) { require_once(HTML_UTIL_COMPONENT_PATH.'/Format.php');}if (defined('HTML_ECOMMERCE_COMPONENT_PATH')) { require_once(HTML_ECOMMERCE_COMPONENT_PATH.'/Tax.php');}/** * Generates the html for a View Basket * <code> * Usage: * $view = new ViewBasket($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); * print $view->getHtml(); * Or * ViewBasket::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); * * Generates a complete View List interface * +-------------------------------- * | Text header * +-------------------------------- * | Qty | Text | Price | Subtotal * +-------------------------------- * | 1 | xyx | 200 | 200,00 * +-------------------------------- * </code> * @package db-basket */class ViewBasket extends ViewList { /** * 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 : $this->getClassName(); // Global table characteristics $theWidth = $width != '' ? $width : BASKET_VIEW_WIDTH; $theClass = $class != '' ? $class : BASKET_VIEW_CLASS; $theBorder = $border != '' ? $border : BASKET_VIEW_BORDER; $theCellPadding = $cellpadding != '' ? $cellpadding : BASKET_VIEW_CELLPADDING; $theCellSpacing = $cellspacing != '' ? $cellspacing : BASKET_VIEW_CELLSPACING; parent::__construct($datareader, $theText, $theWidth, $theClass, $theBorder, $theCellPadding, $theCellSpacing, $summary, $caption, $layout); // TODO define how? element, length, css $multipleEditColumns = array(// SELECT_BASKET_TEXT=>array('text', SELECT_FIELD_LEN_TEXT, CSS_TEXT_CLASS,), SELECT_BASKET_QUANTITY=>array('text', SELECT_FIELD_LEN_QUANTITY, CSS_QUANTITY_CLASS,), // SELECT_BASKET_PRICE=>array('text', SELECT_FIELD_LEN_PRICE, CSS_PRICE_CLASS,), ); $this->setMultipleEditColumns($multipleEditColumns); } /** * Display html * <code> * Usage: * ViewBasket::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 ViewBasket($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); $html->addHtml(); }}?>
Den fulde HTML kildekode for ViewBasket klassen
<? <!-- DEBUG: ViewBasket --> <!-- DEBUG: TableHeader --> <table width="450" class="tableBasketView baseBorder" border="0" cellpadding="2" cellspacing="0"> <tr> <td class="baseArrowHeader" valign="middle"><!-- DEBUG: Link --> <a class="baseLinkColor" href="/source-code/db-basket/ViewBasket/index.php" title="Klik her for at Minimere ... TableHeader"><!-- DEBUG: Images --> <img src="http://humlebier.info/images/arrow-headline.gif" width="4" height="7" alt="arrow-headline.gif" /> </a> </td> <th class="baseColorHeader" valign="top" align="left">ViewBasket (4) </th> </tr> </table> <table id="ViewBasketId" width="450" class="tableBasketView baseBorder" border="0" cellpadding="2" cellspacing="0"> <tr> <th class="baseColorHeader baseNoWrap" valign="top"> <!-- text 100 string --> <!-- DEBUG: Sortby --> <!-- Tekst --><a class="baseColorHeader" href="/source-code/db-basket/ViewBasket/index.php?mvcSORT_BY=asc&mvcORDER_BY=text" title="Mvcorder_by desc">Tekst</a> </th> <th class="baseColorHeader baseNoWrap" valign="top"> <!-- description 100 string --> <!-- DEBUG: Sortby --> <!-- Beskrivelse --><a class="baseColorHeader" href="/source-code/db-basket/ViewBasket/index.php?mvcSORT_BY=asc&mvcORDER_BY=description" title="Mvcorder_by desc">Beskrivelse</a> </th> <th class="baseColorHeader baseNoWrap baseAlignRight" valign="top" align="right"> <!-- quantity 11 float --> <!-- DEBUG: Sortby --> <!-- Antal --><a class="baseColorHeader" href="/source-code/db-basket/ViewBasket/index.php?mvcSORT_BY=asc&mvcORDER_BY=quantity" title="Mvcorder_by desc">Antal</a> </th> <th class="baseColorHeader baseNoWrap baseAlignRight" valign="top" align="right"> <!-- price 11 float --> <!-- DEBUG: Sortby --> <!-- Pris --><a class="baseColorHeader" href="/source-code/db-basket/ViewBasket/index.php?mvcSORT_BY=asc&mvcORDER_BY=price" title="Mvcorder_by desc">Pris</a> </th> <th class="baseColorHeader baseNoWrap baseAlignRight" valign="top" align="right"> <!-- subtotal 11 float --> <!-- DEBUG: Sortby --> <!-- Beløb --><a class="baseColorHeader" href="/source-code/db-basket/ViewBasket/index.php?mvcSORT_BY=asc&mvcORDER_BY=subtotal" title="Mvcorder_by desc">Beløb</a> </th> </tr> <tr> <td class="baseColorDark" valign="top">Hvepse bekæmpelse </td> <td class="baseColorDark" valign="top">Under udhængsbrædder </td> <td class="baseColorDark baseAlignRight" valign="top">1,00 </td> <td class="baseColorDark baseAlignRight" valign="top">650,00 </td> <td class="baseColorDark baseAlignRight" valign="top">650,00 </td> </tr> <tr> <td class="baseColorLight" valign="top">Kørsel </td> <td class="baseColorLight" valign="top">uden for Hillerød </td> <td class="baseColorLight baseAlignRight" valign="top">1,00 </td> <td class="baseColorLight baseAlignRight" valign="top">300,00 </td> <td class="baseColorLight baseAlignRight" valign="top">300,00 </td> </tr> <tr> <td class="baseColorDark" valign="top">Materialer </td> <td class="baseColorDark" valign="top">bekæmpelsesmidler </td> <td class="baseColorDark baseAlignRight" valign="top">2,00 </td> <td class="baseColorDark baseAlignRight" valign="top">50,00 </td> <td class="baseColorDark baseAlignRight" valign="top">100,00 </td> </tr> <tr> <td class="baseColorLight" valign="top">Andet </td> <td class="baseColorLight" valign="top">Alt muligt </td> <td class="baseColorLight baseAlignRight" valign="top">3,00 </td> <td class="baseColorLight baseAlignRight" valign="top">150,00 </td> <td class="baseColorLight baseAlignRight" valign="top">450,00 </td> </tr> <tr> <td class="tableBorderTop baseColorDark" valign="top">Beløb </td> <td class="tableBorderTop baseColorDark baseAlignRight" valign="top" colspan="6">1.500,00 </td> </tr> <tr> <td class="baseColorDark" valign="top">Moms </td> <td class="baseColorDark baseAlignRight" valign="top" colspan="6">375,00 </td> </tr> <tr> <td class="tableBorderTop baseColorLight" valign="top">Ialt </td> <td class="tableBorderTop baseColorLight baseAlignRight" valign="top" colspan="6"> DKK 1.875,00 </td> </tr> </table> ?>
Her er 'klasse metoderne' for ViewBasket klassen:
Her er 'objekt variable' for ViewBasket klassen: