Linux133.fzu.cz

Úvod
MyWiki
PHP
Manuály
Poznámky
Download










Administrace

Třída TImageButton


Třída TImageButton je komponentou ke třídě TForm a je potomkem třídy TButton. TImageButton generuje HTML kód pro zobrazení obrázkového tlačítka ve formuláři.


Popis vlastností


Žádné veřejné - platí k dobrým zvykům OOP, zapouzdřit vlastnosti (proměnné) třídy do metody a zde možné hodnoty řádně ošetřit. Vyhneme se tak možnému nemilému překvapení.


Popis metod


__construct( )
Standardní konstruktor, stará se jen o inicializaci objektu a nemá v tomto případě žádné parametry.


SetImageFile( filename :string )


string: Render( )
Metoda generuje HTML kód pro zobrazení tlačítka podle předem nastavených vlastností pomocí metod třídy TButton. Obyčejně tuhle metodu volá automaticky sám TForm.


Zdrojový kód třídy TImageButton


<?php
class TImageButton extends TButton {
  protected 
$imagefile;    
  
  public function 
__construct(){
    
$this->style "TImageButton";
    }  
  
  public function 
SetImageFile($filename){
    if (!
file_exists($filename)) throw new exception("File was not found.");
    
$this->imagefile $filename;
    }
  
  public function 
Render(){
    if (
$this->name == "") throw new exception("Name is empty.");
    if (
$this->imagefile == "") throw new exception("Image file is not defined.");
    if (
$this->submit$this->onclick "submit();";
    if (
$this->reset$this->onclick "reset();";
    
$code "<A name="$this->name" ";
    if (
$this->alttext !=""$code .= "title="$this->alttext" ";
    if (
$this->style !=""$code .= "class="$this->style" ";
    if (
$this->onclick !=""$code .= "onclick="$this->onclick" ";
    if (
$this->accesskey !=""$code .= "accesskey="$this->accesskey" ";
    
$code .= "><IMG src="$this->imagefile" align="middle" alt="$this->alttext"></A>";
    return 
$code;
    }  
  }  

?>