1.5 Template Project

The Joomla! Documentation Working Group is running a project to develop detailed reference and tutorial material on Joomla! 1.5 templates.  There is a project page on the documentation wiki where you can see the work in progress and help us by contributing your knowledge.

Who's Online

We have 15 guests online

Help Site License

The Joomla! Help Site content is copyright © 2005 - 2008 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution NonCommercial ShareAlike 2.5. Some parts of this website may be subject to other licenses.
Home arrow Developer Manual arrow Appendix arrow C. mosHTML Reference

C. mosHTML Reference PDF Print E-mail
mosHTML Helper Class

mosHTML is a helper class for rendering lists. Following are some examples of how to use the methods in this class.
mosHTML::makeOption

makeOption( string $value [, string $text )

This method returns an object that can be passed in an array to another list handling method. The method takes two arguments, one for the value of the option tag and optionally one for the text to display. If the text is ommitted, the single string is used for both the option value and the text.

Example: creating a list with hard coded values:

// Option value and text will be the same
$mylist1 = array();
$mylist1[] = mosHTML::makeOption( 'Good' );
$mylist1[] = mosHTML::makeOption( 'Bad' );
$mylist1[] = mosHTML::makeOption( 'Ugly' );

// Option value and text will be different
$mylist2 = array();
$mylist2[] = mosHTML::makeOption( '0', 'Select Priority' );
$mylist2[] = mosHTML::makeOption( '1', 'Low' );
$mylist2[] = mosHTML::makeOption( '2', 'High' );

Example: creating a list from a database query:

// alias the 'value' and 'text' fields and the array will
// be in the correct format
$users = array();
$users[] = mosHTML::makeOption( '0', 'Select User' );
$database->setQuery( "SELECT id AS value, username AT text"
  . "nFROM #__users" );

$users = merge_array( $users, $database->loadObjectList() );

The mosHTML method returns a stdClass object with class variables of 'value' and 'text'.
mosHTML::selectList

selectList( array $values, string $tag_name, string $tag_attribs, string $key, string $text, mixed $selected )

The selectList method builds an HTML select tag complete with options. It takes six arguments:

$values - An array of objects that have been returned by a query or the mosHTML method (see above, the $mylist1 and the $mylist2 variables would be suitable).

$tag_name - The name attribute of the select tag.

$tag_attributes - Any additional attributes you want to assign to the select tag.

$key - The name of the class variable holding the option 'value'. Should generally be 'value'.

$text - The name of the class variable holding the option 'text'. Should generally be 'text'.

$selected - Either a string value for a single value select list or an array for a multiple value select list.

Example: a single value select list

// Creates a list select list of the users (see previous example)
// The option tag with the value of zero is selected

$html = mosHTML::selectList( $users, 'size="1" class="inputbox"',
          'value', 'text', 0 );

echo $html;

Example: a multiple value select list

// alias the 'value' and 'text' fields and the array will
// be in the correct format
$users = array();
$users[] = mosHTML::makeOption( '0', 'No User' );
$database->setQuery( "SELECT id AS value, username AT text"
  . "nFROM #__users" );

$users = merge_array( $users, $database->loadObjectList() );

// Get the selected users from a ficticious table
// We only need the 'value' to lookup the selected options
$database->setQuery( "SELECT id AS value"
  . "nFROM #__users_selected" );

$selected = $database->loadObjectList();

// Creates the html
$html = mosHTML::selectList( $users, 'size="10" class="inputbox" multiple="true"',
          'value', 'text', $selected );

echo $html;

mosHTML::integerSelectList

integerSelectList( $start, $end, $inc, $tag_name, $tag_attribs, $selected, $format="" )

The integerSelectList method builds a list of numbers from $start to $end with an increment of $inc. The optional $format argument allows to apply a printf style format to the number.

Example:

$html = mosHTML::integerSelectList( -12, 12, 1, 'tzoffset',
          'size="1" class="inputbox"', 0, "%02d" );

echo $html;

mosHTML::monthSelectList

monthSelectList( $tag_name, $tag_attribs, $selected )

A convenient method for producing a list of months.

$html = mosHTML::monthSelectList( 'month', 'class="inputbox"', '01' );

mosHTML::treeSelectList

Todo.
mosHTML::yesnoSelectList

yesnoSelectList( $tag_name, $tag_attribs, $selected )

A convenient method for producing a simple Yes/No select list.

$html = mosHTML::yesnoSelectList( 'show_banners', 'class="inputbox"', 0 );

mosHTML::radioList

radioList( &$arr, $tag_name, $tag_attribs, $selected=null, $key='value', $text='text' )
mosHTML::yesnoRadioList

yesnoRadioList( $tag_name, $tag_attribs, $selected )

A convenient method for producing a simple Yes/No radio button combination.

$html = mosHTML::yesnoRadioList( 'show_banners', 'class="inputbox"', 0 );

Last Updated ( Thursday, 23 December 2004 )
 
< Prev   Next >