Sådan benyttes komponenten CssImage klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/CssImage.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? CssImage::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new CssImage($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten CssImage klassen
Den fulde PHP kildekode for CssImage klassen
<?php/** * @package base * @see HTML_BASE_PAGE_PATH.'/CssImage.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_COMMON_PATH.'/Html.php');require_once(HTML_BASE_PAGE_PATH.'/Css.php');require_once(HTML_BASE_UTIL_PATH.'/Style.php');require_once(HTML_BASE_UTIL_PATH.'/Images.php');/** * The CSS for the Base package * Generates the Base CSS * <code> * Usage: * $tag = CSS_NAME_BODY; * $url = '/images/background.gif'; * $repeat = CSS_REPEAT_NO; * $position = CSS_POSITION_TOP.' '.CSS_POSITION_RIGHT; * $css = new CssImage($tag, $url, $repeat, $position); * print $css->getHtml(); * Or: * CssImage::display($tag, $url, $repeat, $position); * </code> * @package base */class CssImage extends Style { /** * @var String $tag The tag to use for the background image */ protected $tag = ''; /** * @var String $url The url for the background image */ protected $url = ''; /** * @var String $repeat The repeat directive for the background image */ protected $repeat = ''; /** * @var String $position The position for the background image */ protected $position = ''; /** * Constructor * @param String $tag The tag to use for the background image * @param String $url The url for the background image * @param String $repeat The repeat directive for the background image * @param String $position The position for the background image */ function __construct($tag='', $url='', $repeat='', $position='') { parent::__construct(); $image = new Images(IMAGE_BACKGROUND); $this->tag = $tag != '' ? $tag : CSS_NAME_BODY; $this->url = $url != '' ? $url : $image->getSrcName(); $this->repeat = $repeat != '' ? $repeat : CSS_REPEAT_NO; $this->position = $position != '' ? $position : CSS_POSITION_TOP.' '.CSS_POSITION_RIGHT; } /** * Returns the new Content as an object * @return Object the complete css */ function newCss() { $object = new Raw(); // Body Background Image if (defined('IMAGE_BACKGROUND')) { $image = new Images(IMAGE_BACKGROUND); $css = new Css($this->getClassName()); if (defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) { $object->add(new Raw($css->getHeader("Auto created"))); } $object->add(new Raw($css->getImage($this->tag, $this->url, $this->repeat, $this->position))); } return $object; } /** * Returns the html for the css file * @return String the complete html */ function getHtml() { $html = $this->html; $this->add($this->newCss()); $html .= $this->getStart(); $html .= $this->getCss(); $html .= $this->getEnd(); return $html; } /** * Display html * <code> * Usage: * $tag = CSS_NAME_BODY; * $url = '/images/background.gif'; * $repeat = CSS_REPEAT_NO; * $position = CSS_POSITION_TOP.' '.CSS_POSITION_RIGHT; * CssImage::display($tag, $url, $repeat, $position); * </code> * @static * @param String $tag The tag to use for the background image * @param String $url The url for the background image * @param String $repeat The repeat directive for the background image * @param String $position The position for the background image */ public static function display($tag='', $url='', $repeat='', $position='') { $html = new CssImage($tag, $url, $repeat, $position); $html->addHtml(); }}?>
Den fulde HTML kildekode for CssImage klassen
<? <!-- DEBUG: CssImage --> <style type="text/css"> /*********************************************************** * * AUTOGENERATED file, DO NOT CHANGE OR EDIT, the full source code is here _____________________________________________________ ________| |________ \ | http://Finn-Rasmussen.com Phone (+45) 40 50 60 69 | / \ | Kongens Vænge 79, 3400 Hillerød, Denmark | / / |_____________________________________________________| \ /___________) (__________\ * * @version : 1.11 * @since : 11-Jun-2010 10:49:13 * @copyright : Copyright © 1999-2010 http://Finn-Rasmussen.com * * Email : Please, phone me for my email address * Web : http://Finn-Rasmussen.com * : This website was created by the myPHP taglib and CMS * : Download a free demo of the myPHP taglib here ... * : http://Finn-Rasmussen.com/myPHP/ * @domain : finn-rasmussen.com * @language : da * @webmaster : DEFAULT_CMS_LOGIN_USERNAME(+)finn-rasmussen.com * @file : /cache/files/finn-rasmussen.com-CssImage (Autocreated cache file) * @classname : Auto created ***********************************************************/ body{ background-image : url('/myphp-1.11/myphp-1.11-netbank.eksperter.dk/html/images/waves.jpg'); background-repeat : no-repeat; background-position : top right; } /*********************************************************** * * AUTOGENERATED file, DO NOT CHANGE OR EDIT, the full source code is here _____________________________________________________ ________| |________ \ | http://Finn-Rasmussen.com Phone (+45) 40 50 60 69 | / \ | Kongens Vænge 79, 3400 Hillerød, Denmark | / / |_____________________________________________________| \ /___________) (__________\ * * @version : 1.11 * @since : 11-Jun-2010 10:49:13 * @copyright : Copyright © 1999-2010 http://Finn-Rasmussen.com * * Email : Please, phone me for my email address * Web : http://Finn-Rasmussen.com * : This website was created by the myPHP taglib and CMS * : Download a free demo of the myPHP taglib here ... * : http://Finn-Rasmussen.com/myPHP/ * @domain : finn-rasmussen.com * @language : da * @webmaster : DEFAULT_CMS_LOGIN_USERNAME(+)finn-rasmussen.com * @file : /cache/files/finn-rasmussen.com-CssImage (Autocreated cache file) * @classname : Auto created ***********************************************************/ body{ background-image : url('/myphp-1.11/myphp-1.11-netbank.eksperter.dk/html/images/waves.jpg'); background-repeat : no-repeat; background-position : top right; } </style> ?>
Her er 'klasse metoderne' for CssImage klassen:
Her er 'objekt variable' for CssImage klassen: