blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Table  /  Table   Login nu   Login
blank.gif
 ««« Se kilde koden
blank.gif
triangle.gif Basic Base Component Db Dto Form Form-elements Jquery Layout Menu Menu-fisheye Mvc Tab Table  Template Util
blank.gif
blank.gif
 
arrow-headline.gif Index
 
  Tilbage

Navn : Table.php


Sample code, tutorial

Sådan benyttes komponenten Table klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

  • <?
    require_once(HTML_PACKAGE_PATH.'/Table.php');
    ?>

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

  • <?
    Table
    ::display($param1, $param2, $param3, ...);
    ?>

eller du kan lave en instance af komponenten og benytte metoderne direkte:

  • <?
    $object
    = new Table($param1, $param2, $param3, ...);
    print
    $object->getHtml();
    ?>

Parent html

Sådan vises komponenten Table klassen

Der er ikke fundet noget

PHP source code

Den fulde PHP kildekode for Table klassen

<?
/**
* @package table
* @filesource
* @see HTML_TABLE_COMPONENT_PATH.'/Table.php'
* @copyright (c) http://Finn-Rasmussen.com
* @license http://Finn-Rasmussen.com/license/ myPHP License conditions
* @author http://Finn-Rasmussen.com
* @version 1.10
* @since 22-feb-2007
*/

/**
* The required files
*/
require_once(HTML_BASE_COMMON_PATH.'/Html.php');
require_once(
HTML_BASE_UTIL_PATH.'/Links.php');
require_once(
HTML_TABLE_COMPONENT_PATH.'/TableHeader.php');
require_once(
HTML_TABLE_COMPONENT_PATH.'/Tr.php');
require_once(
HTML_TABLE_COMPONENT_PATH.'/Th.php');
require_once(
HTML_TABLE_COMPONENT_PATH.'/Td.php');
if (
defined('HTML_LOG_UTIL_PATH')) {
    require_once(
HTML_LOG_UTIL_PATH.'/Log.php');
}

/**
* Generates the html for a table
* <code>
* Usage:
*   $table = new Table($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
*   print $table->getHtml();
* Or
*   Table::display($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
*
* Generates a complete table interface
* ---------------------------------
* | Text header
* ---------------------------------
* | head1 | head2 | head3 |
* ---------------------------------
* | dat_1 | dat_2 | dat_3 |
* ---------------------------------
* </code>
* @package table
*/

class Table extends Html {
    
/**
     * @var String $text The text for the table header
     */
    
var $text        = '';

    
// Table data
    
var $width       = '';
    var
$class       = '';
    var
$border      = '';
    var
$cellpadding = '';
    var
$cellspacing = '';
    var
$summary     = '';
    var
$caption     = '';

    
/**
     * Constructor
     * @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
     */
    
function Table($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
        
$this->Html();
        
$this->text = $text;
        if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
            if (
$this->text == '') {
                
//$this->text = $this->getClassName().'(), you forgot to add text';
            
}
        }
        
$theBorder = $border!=''?$border:TABLE_BORDER;
        
$this->width       = $width!=''?$width:TABLE_WIDTH;
        
$this->class       = $class!=''?$class:TABLE_CLASS;
        
$this->border      = $theBorder;
        
$this->cellpadding = $cellpadding!=''?$cellpadding:TABLE_CELLPADDING;
        
$this->cellspacing = $cellspacing!=''?$cellspacing:TABLE_CELLSPACING;
        
$this->summary     = $summary!=''?$summary:'';
        
$this->caption     = $caption!=''?$caption:'';
    }

    
/**
     * Return the html for a table row with no data text inside
     * and optionally a predefined link to click on
     *
     * <code>
     * Generates the following html code:
     *    <td>text</td><td><a href="" title="">back</a></td>
     * Usage:
     *    $text = 'No data found';
     *    $link = LINK_BACK;
     *    $object = $this->newTextRow($text='', $link='');   
     * </code>
     * @param  String $text  The text to show
     * @param  String $link  The name of the link to use. I.e. LINK_BACK
     * @param  String $class The CSS class name to show
     * @return Object The html
     */
    
function newTextRow($text='', $link='', $class='') {
        
$object = new Raw();
        
$td = new Td($class,'','',$text);
        
$object->add($td);
        if (
$link != '') {
            
$links = new Links($link);
            
$td = new Td($class,'','',$links);
            
$object->add($td);
        }
        return
$object;
    }

    
/**
     * Get the Table Header from class TableHeader
     * @return String the html table header
     */
    
function getTableHeader() {
        
$tableheader = new TableHeader($this->text,$this->width,$this->class,$this->border);
        return
$tableheader->getHtml();
    }

    
/**
     * Get the start of the table
     * @return String the html for the start of the table
     */
    
function getStart() {
        
$html  = "\r\n";
        if (
defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_BORDER && $this->border=='0') {
            
$this->border = '1'; // Debug, show border
            
$html .= "<!-- DEBUG_LEVEL_SHOW_BORDER -->\r\n";
        }
        
$html .= '<table';
        
$html .= $this->getAttribute('width');
        
$html .= $this->getAttribute('class');
        
$html .= $this->getAttribute('border');
        
$html .= $this->getAttribute('cellpadding');
        
$html .= $this->getAttribute('cellspacing');
        if (
$this->summary!='') {
            
$html .= $this->getAttribute('summary');
        }
        
$html .= ">\r\n";
        if (
$this->caption!='') {
            
$html .= '<caption>'.$this->caption.'</caption>'."\r\n";
        }
        if (
$this->getSizeof()>0) {
            
$html .= $this->getElements();
        }
        return
$html;
    }

    
/**
     * Get the table end
     * @return String the html
     */
    
function getEnd() {
        return
"</table>\r\n";
    }

    
/**
     * Get the complete html for a table
     * @return String the html
     */
    
function getHtml() {
        
$html  = $this->html;
        
$html .= $this->getTableHeader();
        
$html .= $this->getStart();
        if (
$this->getSizeof()==0) {
            
$tr = new Tr();
            
$tr->add(new Td('','','',TEXT_NO_DATA));
            
$html .= $tr->getHtml();
        } else {
        }
        
$html .= $this->getEnd();
        return
$html;
    }

    
/**
     * Get the start of the table tag
     * <code>
     * Usage:
     *    Table::start($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
     * </code>
     * @static
     * @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
     */
    
function start($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
        
$html = new Table($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
        
$html->addHtml($html->getStart());
    }

    
/**
     * Get the end of the table tag
     * <code>
     * Usage:
     *    Table::end($type);
     * </code>
     * @static
     */
    
function end() {
        
$html = new Html();
        
$html->addHtml(Table::getEnd());
    }

    
/**
     * Display html
     * <code>
     * Usage:
     *    Table::display($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
     * </code>
     * @static
     * @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
     */
    
function display($text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
        
$html = new Table($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
        
$html->addHtml();
    }
}
?>

HTML source code

Den fulde HTML kildekode for Table klassen

<?
<!-- No text in TableHeader -->

<
table width="100%" class="theTable" border="0" cellpadding="2" cellspacing="0">
<
tr>
    <
td valign="top">Der er ikke fundet noget
</td>
</
tr>
</
table>

?>

Class methods

Her er 'klasse metoderne' for Table klassen:

  • object
  • getclassname
  • getmsg
  • addhtml
  • gethtml
  • tostring
  • getcachefilename
  • save
  • content
  • html
  • setobject
  • set
  • get
  • getattribute
  • gettag
  • add
  • getsizeof
  • getelement
  • getelements
  • gettoogle
  • getmaximize
  • getminimize
  • newtriangle
  • display
  • showsource
  • table
  • newtextrow
  • gettableheader
  • getstart
  • getend
  • start
  • end

Object vars

Her er 'objekt variable' for Table klassen:

  • html =>
  • sql =>
  • elements => Array
  • sizeof => 0
  • text =>
  • width => 100%
  • class => theTable
  • border => 0
  • cellpadding => 2
  • cellspacing => 0
  • summary =>
  • caption =>

 
triangle.gif

danmark

Germany

England

France

Italy

Norge

Sverige

USA


 
blank.gif