Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Table  /  Table   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tl.gif Base tr.gif tl.gif Basic tr.gif tl.gif Dto tr.gif tl.gif Form tr.gif tl.gif Language tr.gif tl.gif Layout tr.gif tl.gif Menu tr.gif tl.gif Mvc tr.gif tl.gif Netbank.eksperter.dk tr.gif tl.gif Tab tr.gif tls.gif     Table  trs.gif tl.gif Util tr.gif
blank.gif
blank.gif
arrow-headline.gif Index
MenuLink  MenuLeft  
Tilbage

Skjul: Navn

Table.php


Vis: Sample code, tutorial

Table, 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();
    ?>

Skjul: Sådan vises komponenten

Table, Sådan vises komponenten

Sådan vises komponenten Table klassen

Der er ikke fundet noget

Vis: PHP source code

Table, PHP source code

Den fulde PHP kildekode for Table klassen

<?php
/**
 * @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.11
 * @since 27-nov-2009
 */

/**
 * 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:
 *   $datareader  = null;
 *   $text        = "Text header";
 *   $width       = "100%";
 *   $class       = "theTable";
 *   $border      = "1";
 *   $cellpadding = "5"
 *   $cellspacing = "0";
 *   $summary     = "";
 *   $caption     = "";
 *   $id          = "";
 *   
 *   $table = new Table($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id);
 *   print $table->getHtml();
 * Or
 *   Table::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id);
 *
 * Generates a complete table interface
 * ---------------------------------
 * | Text header
 * ---------------------------------
 * | head1 | head2 | head3 | 
 * ---------------------------------
 * | dat_1 | dat_2 | dat_3 | 
 * ---------------------------------
 * </code>
 * @package table
 */

class Table extends Html {
    
/**
     * @var DataReader The Data Reader object
     */
    
protected $datareader '';

    
/**
     * @var String $text The text for the table header
     */
    
protected $text        '';

    
// Table data
    
protected $width       '';
    protected 
$class       '';
    protected 
$border      '';
    protected 
$cellpadding '';
    protected 
$cellspacing '';
    protected 
$summary     '';
    protected 
$caption     '';
    protected 
$id          '';
    
    
/**
     * Constructor
     * @param DataReader / array $datareader The Data Reader object OR an array
     * @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 
     * @param String $id      The element ID
     */
    
function __construct($datareader=null$text=''$width=''$class=''$border=''$cellpadding=''$cellspacing=''$summary=''$caption=''$id='') {
        
parent::__construct();
        
$this->datareader $this->getDatareader($datareader); 
        
$this->text $text;
        if (
defined('DEBUG_LEVEL_SHOW_INFO') && DEBUG_LEVEL DEBUG_LEVEL_SHOW_INFO) {
            if (
$this->text == '') {
//                $this->text = $this->getClassName().'(), you forgot to add text';
            
}
        }
        
$this->width       $width       != '' $width       TABLE_WIDTH;
        
$this->class       $class       != '' $class       TABLE_CLASS;
        
$this->border      $border      != '' $border      TABLE_BORDER;
        
$this->cellpadding $cellpadding != '' $cellpadding TABLE_CELLPADDING;
        
$this->cellspacing $cellspacing != '' $cellspacing TABLE_CELLSPACING;
        
$this->summary     $summary     != '' $summary     '';
        
$this->caption     $caption     != '' $caption     '';
        
$this->id          $id          != '' $id          '';
    }

    
/**
     * Get the DataReader object or an array to use for this class
     * @param  DataReader / array $datareader The DataReader object, if defined or an array
     * @return DataReader or array The DataReader object or an array of default data
     */
    
private function getDatareader($datareader) {
        
$theDatareader $datareader;
        if (!
is_array($theDatareader) && !is_object($theDatareader) && $theDatareader === '') {
            
$home    = new Links(LINK_HOME);
            
$contact = new Links(LINK_CONTACT);
//            $print   = new Links(LINK_PRINT);
            
$columns = array(
             
LINK_TEXT_HOME=>array('text'=>$home->get('text'),'href'=>$home->get('href'),'title'=>$home->get('title'),),
             
LINK_TEXT_CONTACT_US=>array('text'=>$contact->get('text'),'href'=>$contact->get('href'),'title'=>$contact->get('title'),),
//             LINK_TEXT_PRINT=>array('text'=>$print->get('text'),'href'=>$print->get('href'),'title'=>$print->get('title'),),
            
);
            
$theDatareader $columns;
        }
        return 
$theDatareader;
    }

    
/**
     * 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;
     *    $class  = "";
     *    $object = $this->newTextRow($text='', $link='', $class);   
     * </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();
        
$valign  "";
        
$colspan "";
        
$td = new Td($class$valign$colspan$text);
        
$object->add($td);
        if (
$link != '') {
            
$links = new Links($link);
            
$td = new Td($class$valign$colspan$links);
            
$object->add($td);
        }
        return 
$object;
    }

    
/**
     * Get the Table Header from class TableHeader
     * @return String the html table header
     */
    
function getTableHeader() {
        
// , $this->cellpadding, $this->cellspacing, $this->summary, $this->caption
        
$datareader null;
        
$tableheader = new TableHeader($datareader$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_SHOW_BORDER') && 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('id');
        
$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 {
            
// Data have to be added
        
}
        
$html .= $this->getEnd();
        return 
$html;
    }

    
/**
     * Get the start of the table tag
     * <code>
     * Usage:
     *    Table::start($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); 
     * </code>
     * @static
     * @param DataReader / array $datareader The Data Reader object OR an array
     * @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 
     * @param String $id      The element ID
     */
    
public static function start($datareader=null$text=''$width=''$class=''$border=''$cellpadding=''$cellspacing=''$summary=''$caption=''$id='') {
        
$html = new Table($datareader$text$width$class$border$cellpadding$cellspacing$summary$caption$id);
        
$html->addHtml($html->getStart());
    }

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

    
/**
     * Display html
     * <code>
     * Usage:
     *    Table::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $id); 
     * </code>
     * @static
     * @param DataReader / array $datareader The Data Reader object OR an array
     * @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
     * @param String $id      The element ID
     */
    
public static function display($datareader=null$text=''$width=''$class=''$border=''$cellpadding=''$cellspacing=''$summary=''$caption=''$id='') {
        
$html = new Table($datareader$text$width$class$border$cellpadding$cellspacing$summary$caption$id);
        
$html->addHtml();
    }
}
?>

Vis: HTML source code

Table, HTML source code

Den fulde HTML kildekode for Table klassen

<?
<!-- DEBUGTable -->
<!-- 
DEBUGTableHeader -->
<!-- 
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>

?>

Vis: Class methods

Table, Class methods

Her er 'klasse metoderne' for Table klassen:

  • __construct
  • newTextRow
  • getTableHeader
  • getStart
  • getEnd
  • getHtml
  • start
  • end
  • display
  • setObject
  • set
  • get
  • getAttribute
  • getTag
  • add
  • getSizeof
  • getElement
  • getElements
  • getToogle
  • getMaximize
  • getMinimize
  • newTriangle
  • getStartHtml
  • getEndHtml
  • showsource
  • getClassName
  • getMsg
  • addHtml
  • __toString
  • getCacheFileName
  • save
  • content

Vis: Object vars

Table, Object vars

Her er 'objekt variable' for Table klassen:

  • html =>
  • sql =>

MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


 
blank.gif
MenuBottom 
triangle.gif Copyright @ 1999-2010 www.Finn-Rasmussen.com Powered by myPHP Version (5.2.6-1+lenny8) 1.11
blank.gif