Sådan benyttes komponenten IndexMenu klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/IndexMenu.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? IndexMenu::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new IndexMenu($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten IndexMenu klassen
Den fulde PHP kildekode for IndexMenu klassen
<?php/** * @package tab * @see HTML_TAB_PAGE_PATH/IndexMenu.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_UTIL_COMPONENT_PATH.'/Request.php');/** * Generates a list of links, like in an Index * <code> * Usage: * $documents = array('Message','MessageList','Redirect','Rowcolor','Singleton',); * $indexMenuLinks = IndexMenu:links($documents); * Or * $file = IndexMenu::file($PACKAGES); * </code> * @package tab */class IndexMenu { /** * Constructor */ function __construct() { } /** * Get the filename name for the Index source code * The global package name is expected * @see $PACKAGES * <code> * Usage: * $phpFile = DEFAULT_CONTENT_FILE_NAME; * $file = IndexMenu::file($PACKAGES, $phpFile); * </code> * @static * @param array $packages The array of packages * @param String $phpFile The php filename to use * @return String The filename to include or empty if not found */ public static function file($packages, $phpFile) { $filename = ''; $indexSourceCode = defined('INDEX_DEFAULT')?INDEX_DEFAULT:""; $tabSourceCode = TAB_INDEX; if (defined('TAB_SHOW') && TAB_SHOW & TAB_SHOW_URL) { $indexSourceCode = Request::get(REQUEST_INDEX, defined('INDEX_DEFAULT')?INDEX_DEFAULT:""); $tabSourceCode = Request::get(REQUEST_TAB, TAB_INDEX); } foreach($packages as $key=>$package) { if (defined($package)) { $path = constant($package); if (MYPHP_RUNTIME != '') { // Use the real software as path $path = str_replace(MYPHP_RUNTIME, '', $path); } $file = $path.DEFAULT_HTML_DOC_PATH.($indexSourceCode != ''?"$indexSourceCode":'')."/".$phpFile; if (file_exists($file)) { //print "OK exists $file<br />"; //$file = constant($package).DEFAULT_HTML_DOC_PATH.$phpFile; } else { //print "not $file<br />"; $file = $path.DEFAULT_HTML_DOC_PATH.$phpFile; } if (file_exists($file)) { $text = substr(basename(constant($package)), strlen(MYPHP_PREFIX.CURRENT_VERSION)); if ( $text == $tabSourceCode ) { $filename = $file; //print "require $key $file<br />\r\n"; break; } else { // Ignore //print "Ignore $text $key $file<br />\r\n"; } } else { // Ok // print "Not exists $key $file<br />\r\n"; } } else { // Ok, not part of the packages // print "Not part of package $key $package<br />\r\n"; } } return $filename; } /** * Get the array of index menu links * <code> * Usage: * $documents = array('Message','MessageList','Redirect','Rowcolor','Singleton',); * $indexMenuLinks = IndexMenu::links($documents); * </code> * @static * @param array $documents The array of index links * @return array The rows of array links for the Index.php */ public static function links($documents) { $indexmenuLinks = array(); $isRequest = false; if (defined('TAB_SHOW') && TAB_SHOW & TAB_SHOW_URL) { $isRequest = true; } $params = ''; $tabSourceCode = TAB_INDEX; $port = Server::getServerPort(); if ($port != '80') { $port = ":$port"; } else { $port = ''; } $domainNameSourceCode = 'http:/'.'/'.(DOMAIN_NAME!='localhost'?DOMAIN_NAME_SOURCE_CODE:DOMAIN_NAME).$port; $urlencode = true; $object = new Params(); if ($isRequest) { $params = $object->get(array(REQUEST_INDEX=>''), $urlencode, __FILE__, __LINE__); $indexmenuLinks[] = array('text'=>LINK_TEXT_OVERVIEW,'href'=>$domainNameSourceCode.$params,'aux'=>LINK_LAYOUT_LI,'class'=>'','title'=>LINK_TITLE_OVERVIEW,); } else { $params = $object->get(array(), $urlencode, __FILE__, __LINE__); $indexmenuLinks[] = array('text'=>LINK_TEXT_OVERVIEW,'href'=>$domainNameSourceCode.$GLOBALS[LINK_NAME_HREF ][LINK_SOURCE_CODE].'/'.$tabSourceCode.$params,'aux'=>LINK_LAYOUT_LI,'class'=>'','title'=>LINK_TITLE_OVERVIEW,); } foreach($documents as $document) { if ($isRequest) { $params = $object->get(array(REQUEST_INDEX=>$document), $urlencode, __FILE__, __LINE__); $indexmenuLinks[] = array('text'=>$document,'href'=>$domainNameSourceCode.$params,'aux'=>LINK_LAYOUT_LI); } else { $params = $object->get(array(), $urlencode, __FILE__, __LINE__); $indexmenuLinks[] = array('text'=>$document,'href'=>$domainNameSourceCode.$GLOBALS[LINK_NAME_HREF ][LINK_SOURCE_CODE].'/'.$tabSourceCode.'/'.$document.$params,'aux'=>LINK_LAYOUT_LI); } } return $indexmenuLinks; } /** * Builds the html for an Index menu, and return it * @return String The Index menu as html */ function getHtml() { $html = ''; $documents = array('Message','MessageList','Redirect','Rowcolor','Singleton',); $indexmenuLinks = IndexMenu::links($documents); foreach($indexmenuLinks as $no=>$links) { $row = ''; foreach($links as $key=>$value) { $row .= "$key=>$value "; } $html .= "$no) $row<br />\r\n"; } return $html; }}?>
Den fulde HTML kildekode for IndexMenu klassen
<? 0) text=>Oversigt href=>http://finnrasmussen.dk/source-code/tab aux=>16 class=> title=>Klik her for at se oversigten ... <br /> 1) text=>Message href=>http://finnrasmussen.dk/source-code/tab/Message aux=>16 <br /> 2) text=>MessageList href=>http://finnrasmussen.dk/source-code/tab/MessageList aux=>16 <br /> 3) text=>Redirect href=>http://finnrasmussen.dk/source-code/tab/Redirect aux=>16 <br /> 4) text=>Rowcolor href=>http://finnrasmussen.dk/source-code/tab/Rowcolor aux=>16 <br /> 5) text=>Singleton href=>http://finnrasmussen.dk/source-code/tab/Singleton aux=>16 <br /> ?>
Her er 'klasse metoderne' for IndexMenu klassen:
Her er 'objekt variable' for IndexMenu klassen: