|
Introduction
OK here it is, by popular demand (well, not really but....), the initial release of ice2Libs. ice2Libs are intended to be a set of php libs which will enable the rapid creation of php web sites and applications. This first release is bundled with iceGrab and includes ice_htmlTable, a class to produce html tables (surprisingly enough). ice_htmlTable objects can be manipulated easily allowing you to change the appearance and content of tables on the fly.
Examples
The best way to show this is with a simple example. Take the code below:
$table = new ice_htmlTable();
$table -> set_cellpadding(3);
$table -> set_border(2);
$table -> set_bgColor('green');
// Individual cell properties are set up using an
// array of the form:
// array(Content/text, column, row, colspan,
rowspan)
// And they may also contain any legal cell html
// attributes in the form 'attribute' => 'value'
$cells[] = array('A title cell', 1, 1, 2, 1, 'align' => 'center', 'bgcolor' => 'blue');
$cells[] = array('A content cell', 1, 2, 1, 1, 'align' => 'center');
$cells[] = array('Another cell', 2, 2, 1, 1, 'width' => '80%');
//The table can be built by feeding an array of cell
//property arrays to the set_cells method
$table -> set_cells($cells);
$table -> show();
Produces the following (ugly) table:
|
A title cell
|
|
A content cell
|
Another cell
|
As well as ice_htmlTable, this first release also includes ice_htmlForm, a set of classes for producing forms. ice_htmlForm objects can be easily linked to a database allowing you to rapidly produce web applications. This is made even easier with ice_dbClass (to be released soon). An example follows:
// Create a table to contain our form.
$table = new ice_htmlTable();
$table -> set_border(1);
$table -> set_bgColor('white');
// Set up the form header
$formHeader = array(
'method' => 'post',
'action' => 'index.php',
);
$table -> set_formHead($formHeader);
// Most form elements take the form:
// ice_elementName(label, name, defaultValue)
// First, a few example drop down lists.
//
// A range of numbers, 0 - 100 going up in
// increments of 10
$numbers = new ice_rangeSelectList('Range', 'numbers', 0, 100, 10);
// A date select. Defaults to today.
$date = new ice_dateTimeSelectList('Date', 'date');
// An array of values for our name list:
// array('value' => 'text')
$names = array(
'1' => 'Bob',
'3' => 'Mike',
'6' => 'Jane',
'7' => 'Terry'
);
$nameList = new ice_idSelectList('Names', 'names', $names);
// Set the selected value to Mike.
$nameList -> set_selected('Mike');
// Include a blank option.
$nameList -> set_blank(1);
// A text box.
$defaultText = 'default';
$text = new ice_textEntry('Text Box', 'text', $defaultText);
$text -> set_layout(1);
// A read-only text area.
$message = "This is a message in a read only text area.";
$textArea = new ice_textArea('A message', 'message', $message);
$textArea -> set_readOnly(1);
$textArea -> set_layout(2);
// Set up the cells for the table. We get the html of
// each form element using the get_html() method
$cells[] = array('A Title', 1, 1, 2, 1, 'align' => 'center', 'bgcolor' => 'blue');
$cells[] = array($numbers -> get_html(), 1, 2, 1, 1);
$cells[] = array($nameList -> get_html(), 2, 2, 1, 1);
$cells[] = array($date -> get_html(), 1, 3, 2, 1, 'align' => 'center');
$cells[] = array($text -> get_html(), 1, 4, 2, 1, 'align' => 'center');
$cells[] = array($textArea -> get_html(), 1, 5, 2, 1, 'align' => 'center');
$table -> set_cells($cells);
$table -> show();
Produces the following:
The code generated by ice2Libs is valid XHTML 1.0 Transitional.
Download ice2Libs v0.0.1
Included in this distribution:
- ice_htmlTable
- ice_htmlForm
- iceGrab - news grabber
Grab the tarball here - ice2Libs_0.0.1.tar.gz
License
ice2Libs are released under the The GNU General Public License (GPL) so they're free (as in beer and freedom). Feel free to use them on your site or in your applications. If you're wondering how to pay for this code, well, while any cheques, computer equiptment, chocolate is greatly achieved and all major credit cards are accepted, the real payment is in contribution. If you think there's something lacking or you find a bug, let me know and I'll try to put it right, alternatively if you write code that you think could benefit ice2Libs send it to me and get involved in the developement. Also, if you do use the code, a mention as to where you got it wouldn't go amiss.
|