Sådan benyttes komponenten Engine klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/Engine.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? Engine::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new Engine($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten Engine klassen
Den fulde PHP kildekode for Engine klassen
<?php/** * @package mvc * @see HTML_MVC_CONTROLLER_PATH.'/Engine.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_CONTROLLER_PATH.'/EngineObject.php');require_once(HTML_DB_LOGIN_QUERY_PATH.'/QueryLogin.php');/** * The Engine is the controller for other EngineXyz objects * This is the controller for a List View or Form View * where the user may Insert, Update or delete records * <code> * Usage: * $table = DATABASE_PREFIX.TABLE_NAME_LOGIN; * $query = new QueryLogin($table); * $name = ENGINE_NAME_LOGIN; * $view = GRID_LAYOUT_VIEW_LOGIN; * $sort = true; * $validators = ""; * * $engine = new Engine($table, $query, $name, $view, $sort, $validators); * print $engine->getHtml(); * Or * Engine::display($table, $query, $name, $view, $sort, $validators); * </code> * @package mvc */class Engine extends EngineObject { /** * Constructor * @param String $table The table to use * @param Query $query The Query Object to use * @param String $name The Engine Name to use * @param String $view The View to use * @param boolean $sort The DataReader object may be sorted * @param array $validators The validators to use */ function __construct($table='', $query='', $name='', $view='', $sort='', $validators='') { $theTable = $table != '' ? $table : DATABASE_PREFIX.TABLE_NAME_LOGIN; $theQuery = $query != '' ? $query : new QueryLogin($theTable); $theName = $name != '' ? $name : ENGINE_NAME_LOGIN; $theView = $view != '' ? $view : GRID_LAYOUT_VIEW_LOGIN; $theSort = $sort != '' ? $sort : true; $theValidators = $validators != '' ? $validators : ""; parent::__construct($theTable, $theQuery, $theName, $theView, $theSort, $theValidators); } /** * Display html * <code> * Usage: * Engine::display($table, $query, $name, $view, $sort, $validators); * </code> * @static * @param String $table The table to use * @param Query $query The Query Object to use * @param String $name The Engine Name to use * @param String $view The View to use * @param boolean $sort The DataReader object may be sorted * @param array $validators The validators to use */ public static function display($table='', $query='', $name='', $view='', $sort='', $validators='') { $html = new Engine($table, $query, $name, $view, $sort, $validators); $html->addHtml(); }}?>
Den fulde HTML kildekode for Engine klassen
<? <!-- DEBUG: Engine --> <!-- DEBUG: ViewLimit --> <!-- ViewLimit->getHtml(), (numRows:0) (rows/max:0) (max:400) --> <!-- DEBUG: ViewLogin --> <!-- DEBUG: TableHeader --> <table width="323" class="formView baseBorder" border="0" cellpadding="2" cellspacing="0"> <tr> <td class="baseArrowHeader" valign="middle"><!-- DEBUG: Link --> <a class="baseLinkColor" href="/source-code/mvc/Engine/index.php" title="Klik her for at Minimere ... TableHeader"><!-- DEBUG: Images --> <img src="http://finnrasmussen.dk/images/arrow-headline.gif" width="4" height="7" alt="arrow-headline.gif" /> </a> </td> <th class="baseColorHeader" valign="top" align="left">EngineLogin (0) </th> </tr> </table> <table id="ViewLoginId" width="323" class="formView baseBorder" border="0" cellpadding="10" cellspacing="0"> <tr> <td valign="top"><!-- DEBUG: Script --> <script type="text/javascript"> //<![CDATA[ function onSubmitViewLogin(theForm) { var isValid = true; var messages = ''; var focusMe = ''; if (typeof theForm.username == 'object' && theForm.username.value == '') { isValid = false; if (focusMe === '') { focusMe = theForm.username.name; } messages += "Brugernavn eller Nr.\r\n"; } if (typeof theForm.password == 'object' && theForm.password.value == '') { isValid = false; if (focusMe === '') { focusMe = theForm.password.name; } messages += "Adgangskode\r\n"; } if (typeof theForm.email == 'object' && theForm.email.value == '') { isValid = false; if (focusMe === '') { focusMe = theForm.email.name; } messages += "Email\r\n"; } if (typeof theForm.isOnline == 'object' && theForm.isOnline.value == '') { isValid = false; if (focusMe === '') { focusMe = theForm.isOnline.name; } messages += "isOnline\r\n"; } if (!isValid) { var msg = "Udfyld felterne:\r\n"; msg += '===================\r\n'; msg += messages; alert(msg); } else { var submitId = document.getElementById('submitButtonViewLoginId'); submitId.value = ' ...'; submitId.disabled = true; submitId.className = 'formButton baseBorder baseBody formXXSmall formButtonBee'; } if (!isValid && focusMe !== '') { theForm[focusMe].focus(); } return isValid; } //]]> </script> <!-- DEBUG: Form --> <form action="/source-code/mvc/Engine/index.php" method="post" name="ViewLogin" id="Form5" onsubmit="return onSubmitViewLogin(this);"> <div class="baseAlignRight" align="right">No help</div> <!-- DEBUG: Hiddens --> <!-- Hiddens ViewLogin --> <!-- DEBUG: Hidden --> <input type="hidden" name="baseCOMMAND" value="85d3993b942fa1ea46c94653aac9400f" title="85d3993b942fa1ea46c94653aac9400f (ViewLogin)" /> <!-- username 100 string demo_login not_null --> <!-- DEBUG: Label --> <label for="Label1" accesskey="B" title="Accelerator key, use (Alt + B)"> <b><span class="baseColorDark">B</span>rugernavn eller Nr. (Skal udfyldes)</b> (Alt + B) </label><br /> <!-- DEBUG: Text --> <input type="text" name="username" id="Label1" class="formXLARGE baseBorder baseBody" maxlength="100" value="" title="username
100
string
demo_login
not_null
" tabindex="1" /><br /> <!-- password 100 string demo_login not_null --> <!-- DEBUG: Label --> <label for="Label2" accesskey="A" title="Accelerator key, use (Alt + A)"> <b><span class="baseColorDark">A</span>dgangskode (Skal udfyldes)</b> (Alt + A) </label><br /> <!-- DEBUG: Password --> <input type="password" name="password" id="Label2" class="formXLARGE baseBorder baseBody" maxlength="100" value="" title="password
100
string
demo_login
not_null
" tabindex="2" /><br /> <!-- email 100 string demo_login not_null --> <!-- DEBUG: Label --> <label for="Label3" accesskey="E" title="Accelerator key, use (Alt + E)"> <b><span class="baseColorDark">E</span>mail (Skal udfyldes)</b> (Alt + E) </label><br /> <!-- DEBUG: Text --> <input type="text" name="email" id="Label3" class="formXLARGE baseBorder baseBody" maxlength="100" value="" title="email
100
string
demo_login
not_null
" tabindex="3" /><br /> <!-- isOnline 1 string demo_login not_null enum --> <!-- DEBUG: Checkbox --> <input type="checkbox" id="Checkbox4" onclick="if(this.checked){this.form.elements['isOnline'].value='Y';}else{this.form.elements['isOnline'].value='N';}" class="baseBody" checked="checked" value="Y" title="isOnline
1
string
demo_login
not_null
enum
" tabindex="4" /> <!-- DEBUG: Label --> <label for="Checkbox4" accesskey="I" title="Accelerator key, use (Alt + I)"> <b><span class="baseColorDark">I</span>sOnline (Skal udfyldes)</b> (Alt + I) </label><br /> <!-- DEBUG: Hidden --> <input type="hidden" name="isOnline" value="Y" /> <!-- DEBUG: Buttons --> <p><div class="baseAlignCenter"><!-- DEBUG: CancelButton --> <input type="button" class="formButton baseBorder baseBody formXXSmall" onclick="history.back();" value="Fortryd" title="Fortryd" tabindex="5" /> <!-- DEBUG: ResetButton --> <input type="reset" class="formButton baseBorder baseBody formXXSmall" value="Nulstil" title="Nulstil (Alt + Z)" tabindex="6" accesskey="Z" /> <!-- BUTTON_SUBMIT_TEXT --> <!-- DEBUG: SubmitButton --> <input type="submit" id="submitButtonViewLoginId" class="formButton baseBorder baseBody formXXSmall" value="Go" title="Go (Alt + G)" tabindex="7" accesskey="G" /> </div> </p> </form> <!-- DEBUG: Focus --> <script type="text/javascript"> //<![CDATA[ function setFocus_ViewLoginusername() { if (typeof document.ViewLogin == 'object') { if (typeof document.ViewLogin.username == 'object') { document.ViewLogin.username.focus(); document.ViewLogin.username.select(); } } } if (typeof focusIsDefined == 'undefined') { function onload1Body() { var onloadCurrent = window.onload; if (typeof onloadCurrent !== 'function') { window.onload = setFocus_ViewLoginusername; } else { window.onload = function() { onloadCurrent(); setFocus_ViewLoginusername(); } } } onload1Body(); focusIsDefined = true; } //]]> </script> </td> </tr> </table> <!-- DEBUG: ViewLimit --> <!-- ViewLimit->getHtml(), (numRows:0) (rows/max:0) (max:400) --> ?>
Her er 'klasse metoderne' for Engine klassen:
Her er 'objekt variable' for Engine klassen: