HOME   SITEMAP   CONTACT   NEWS   BLOG
Search


Framework HTML Table Style


Predefined styles (in the form of XML strings or PHP arrays) can be applied to any data (with an arbitrary number of rows and columns).

Example:

This is the needed PHP code:

<?php
require_once($APP['path']['core'] . 'html/table/Bs_HtmlTableStyle.class.php');
$data = array(
  array(
'Country''City 1',   'City 2'), 
  array(
'Canada''Vancouver''Toronto'), 
  array(
'France''Paris',     'Lyon'), 
  array(
'Russia''Moskau',    'Dabady'), 
);
$style = array(
  
'head'     => '<table border="1" cellpadding="2" cellspacing="0">'
  
'foot'     => '</table>'
  
'empty'    => '&nbsp;'
  
'firstrow' => array(
    
'head'      => '<tr>'
    
'foot'      => '</tr>'
    
'cell'      => '<td bgcolor="yellow">__DATA__</td>'
  ), 
  
'row'      => array(
    
'head'      => '<tr>'
    
'foot'      => '</tr>'
    
'firstcell' => '<td bgcolor="yellow">__DATA__</td>'
    
'cell'      => '<td>__DATA__</td>'
  ), 
);
$hts =& new Bs_HtmlTableStyle;
$hts->setData($data);
$hts->setStyle($style);
echo 
$hts->toHtml();
?>


And this is how the table looks:

CountryCity 1City 2
CanadaVancouverToronto
FranceParisLyon
RussiaMoskauDabady


XML Version:
In the CMS we define the table structure in XML files instead of PHP arrays, like this:
<bs:part name="tableLayout" mime="tableLayout">
  <bs:head>
    <![CDATA[
    <table border="0" cellspacing="0" cellpadding="3">
    ]]>
  </bs:head>
  <bs:foot>
    <![CDATA[
    </table>
    ]]>
  </bs:foot>
  <bs:empty>
    <![CDATA[
    No content.
    ]]>
  </bs:empty>
  <bs:firstrow>
    <bs:head>
      <![CDATA[
      <tr bgcolor="#F7E59B">
      ]]>
    </bs:head>
    <bs:cell>
      <![CDATA[
      <td valign="top"><b>__DATA__</b></td>
      ]]>
    </bs:cell>
    <bs:foot>
      <![CDATA[
      </tr>
      ]]>
    </bs:foot>
  </bs:firstrow>
  <bs:row>
    <bs:head>
      <![CDATA[
      <tr>
      ]]>
    </bs:head>
    <bs:cell>
      <![CDATA[
      <td valign="top">__DATA__</td>
      ]]>
    </bs:cell>
    <bs:lastcell>
      <![CDATA[
      <td valign="top" align="right"><nobr>__DATA__</nobr></td>
      ]]>
    </bs:lastcell>
    <bs:foot>
      <![CDATA[
      </tr>
      ]]>
    </bs:foot>
  </bs:row>
  <bs:row>
    <bs:head>
      <![CDATA[
      <tr><td colspan="100%" height="1"><img src="/img/dotBlack.gif" width="100%" height="1" border="0"/></td></tr><tr>
      ]]>
    </bs:head>
    <bs:cell>
      <![CDATA[
      <td valign="top">__DATA__</td>
      ]]>
    </bs:cell>
    <bs:lastcell>
      <![CDATA[
      <td valign="top" align="right"><nobr>__DATA__</nobr></td>
      ]]>
    </bs:lastcell>
    <bs:foot>
      <![CDATA[
      </tr>
      ]]>
    </bs:foot>
  </bs:row>
</bs:part>


Documentation:

  • Check out the API-Doc for this class.

Download:

This class ships with the BlueShoes Framework. See the download page.


Let us know

Have you done something interesting with BlueShoes or one of its components?