Class FormOptionsHelper

(line 55)

Description

AkActionViewHelper
   |
   --FormOptionsHelper

Located in File: /AkActionView/helpers/form_options_helper.php

Provides a number of methods for turning different kinds of containers into a set of option tags.

== Options The <tt>collection_select</tt>, <tt>country_select</tt>, <tt>select</tt>, and <tt>time_zone_select</tt> methods take an <tt>options</tt> parameter, an array.

* <tt>include_blank</tt> - set to true if the first option element of the select element is a blank. Useful if there is not a default value required for the select element. For example,

$form_options_helper->select('post','category', $Post->categories, array('include_blank'=>true));

could become:

<select name="post[category]"> <option></option> <option>joke</option> <option>poem</option> </select>

* <tt>prompt</tt> - set to true or a prompt string. When the select element doesn't have a value yet, this prepends an option with a generic prompt -- "Please select" -- or the given prompt string.

Another common case is a select tag for an <tt>belongs_to</tt>-associated object. For example,

$form_options_helper->select('post', 'person_id', $Person->collect($Person->find(), 'name', 'id'));

could become:

<select name="post[person_id]"> <option value="1">David</option> <option value="2">Sam</option> <option value="3">Tobias</option> </select>



Classes extended from FormOptionsHelper:
AkFormOptionsHelperBuilder
Provides a number of methods for turning different kinds of containers into a set of option tags.

Class Variables

Summary:

Class Constants

Summary:

Method Detail

Summary:
void collection_select ( $object_name,  $column_name,  $collection,  $value_column_name,  $text_column_name, [ $options = array()], [ $html_options = array()])
void country_options_for_select ([ $selected = null], [ $priority_countries = array()], [ $model = 'AkCountries'], [ $options = array()])
void country_select ( $object_name,  $column_name, [ $priority_countries = null], [ $options = array()], [ $html_options = array()])
void options_for_select ( $container, [ $selected = array()], [ $options = array()])
void options_from_collection_for_select ( $collection,  $value_column_name, [ $text_column_name = null], [ $selected_value = array()], [ $options = array()])
void option_groups_from_collection_for_select ( $collection,  $group_method,  $group_label_method,  $option_key_method,  $option_value_method, [ $selected_key = null])
void select ( $object_name,  $column_name,  $choices, [ $options = array()], [ $html_options = array()])
void time_zone_options_for_select ([ $selected = null], [ $priority_zones = array()], [ $model = 'AkTimeZone'])
void time_zone_select ( $object_name,  $column_name, [ $priority_zones = array()], [ $options = array()], [ $html_options = array()])

Method collection_select (line 94)

void collection_select( $object_name, $column_name, $collection, $value_column_name, $text_column_name, [ $options = array()], [ $html_options = array()])

Overridden in child classes as:

AkFormOptionsHelperBuilder::collection_select()

Return select and option tags for the given object and column_name using options_from_collection_for_select to generate the list of option tags.

Parameters

  • $object_name:
  • $column_name:
  • $collection:
  • $value_column_name:
  • $text_column_name:
  • $options:
  • $html_options:

Info

Method country_options_for_select (line 272)

void country_options_for_select( [ $selected = null], [ $priority_countries = array()], [ $model = 'AkCountries'], [ $options = array()])

Returns a string of option tags for pretty much any country in the world. Supply a country name as +selected+ to have it marked as the selected option tag. You can also supply an array of countries as +priority_countries+, so that they will be listed above the rest of the (long) list.

NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.

Parameters

  • $selected:
  • $priority_countries:
  • $model:
  • $options:

Info

Method country_select (line 103)

void country_select( $object_name, $column_name, [ $priority_countries = null], [ $options = array()], [ $html_options = array()])

Overridden in child classes as:

AkFormOptionsHelperBuilder::country_select()

Return select and option tags for the given object and column_name, using country_options_for_select to generate the list of option tags.

Parameters

  • $object_name:
  • $column_name:
  • $priority_countries:
  • $options:
  • $html_options:

Info

Method options_for_select (line 149)

void options_for_select( $container, [ $selected = array()], [ $options = array()])

Accepts a container array and returns a string of option tags. Given a container where the elements respond to first and

last (such as a two-element array), the "lasts" serve as option values and the "firsts" as option text. Arrays are turned into this form automatically, so the keys become "firsts" and values become lasts. If +selected+ is specified, the matching "last" or element will get the selected option-tag. +Selected+ may also be an array of values to be selected when using a multiple select.

Examples (call, result): $form_options_helper->options_for_select(array('Dollar'=>'$', 'Kroner'=>'DKK')); <option value="$">Dollar</option><option value="DKK">Kroner</option>

$form_options_helper->options_for_select(array('VISA', 'MasterCard'), 'MasterCard'); <option value="VISA">VISA</option><option selected="selected" value="MasterCard">MasterCard</option>

$form_options_helper->options_for_select(array('Basic'=>'$20','Plus'=>'$40'), '$40'); <option value="$20">Basic</option><option selected="selected" value="$40">Plus</option>

$form_options_helper->options_for_select(array('VISA','MasterCard','Discover'), array('VISA','Discover')); <option selected="selected" value="VISA">VISA</option> <option value="MasterCard">MasterCard</option> <option selected="selected" value="Discover">Discover</option>

NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.

Parameters

  • $container:
  • $selected:
  • $options:

Info

Method options_from_collection_for_select (line 185)

void options_from_collection_for_select( $collection, $value_column_name, [ $text_column_name = null], [ $selected_value = array()], [ $options = array()])

Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning the the result of a call to the +value_column_name+ as the option value and the +text_column_name+ as the option text.

If +$selected_value+ is specified, the element returning a match on +value_column_name+ will get the selected option tag.

Example (call, result). Imagine a loop iterating over each +person+ in <tt>$Project->People</tt> to generate an input tag: $form_options_helper->options_from_collection_for_select($Project->People,'id','name'); <option value="{$Person->id}">{$Person->name}</option>

NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.

Parameters

  • $collection:
  • $value_column_name:
  • $text_column_name:
  • $selected_value:
  • $options:

Info

Method option_groups_from_collection_for_select (line 237)

void option_groups_from_collection_for_select( $collection, $group_method, $group_label_method, $option_key_method, $option_value_method, [ $selected_key = null])

Returns a string of option tags, like options_from_collection_for_select, but surrounds them with <optgroup> tags.

An array of group objects are passed. Each group should return an array of options when calling group_method Each group should return its name when calling group_label_method.

$form_options_helper->option_groups_from_collection_for_select($continents, 'getCountries', 'getContinentName', 'getCountryId', 'getCountryName', $selected_country->id);

Could become: <optgroup label="Africa"> <option value="EGP">Egipt</option> <option value="RWD">Rwanda</option> .... </optgroup>

<optgroup label="Asia"> <option value="ZHN">China</option> <option value="IND">India</option> <option selected="selected" value="JPN">Japan</option> ..... </optgroup>

with objects of the following classes: class Continent{ function Continent($p_name, $p_countries){ $this->continent_name = $p_name; $this->countries = $p_countries;} function getContinentName(){ return $this->continent_name; } function getCountries(){ return $this->countries; } } class Country { function Country($id, $name){ $this->id = $id; $this->name = $name; } function getCountryId(){ return $this->id; } function getCountryName(){ return $this->name;} }

NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.

Parameters

  • $collection:
  • $group_method:
  • $group_label_method:
  • $option_key_method:
  • $option_value_method:
  • $selected_key:

Info

Method select (line 85)

void select( $object_name, $column_name, $choices, [ $options = array()], [ $html_options = array()])

Overridden in child classes as:

AkFormOptionsHelperBuilder::select()

Create a select tag and a series of contained option tags for the provided object and method.

The option currently held by the object will be selected, provided that the object is available. See options_for_select for the required format of the choices parameter.

Example with $Post->person_id => 1: $form_options_helper->select('post', 'person_id', $Person->collect($Person->find(), 'name', 'id'), array(), array('include_blank'=>true));

could become:

<select name="post[person_id]"> <option></option> <option value="1" selected="selected">David</option> <option value="2">Sam</option> <option value="3">Tobias</option> </select>

This can be used to provide a default set of options in the standard way: before rendering the create form, a new model instance is assigned the default options and bound to $this->model_name. Usually this model is not saved to the database. Instead, a second model object is created when the create request is received. This allows the user to submit a form page more than once with the expected results of creating multiple records. In addition, this allows a single partial to be used to generate form inputs for both edit and create forms.

By default, $post.person_id is the selected option. Specify 'selected' => value to use a different selection or 'selected' => null to leave all options unselected.

Parameters

  • $object_name:
  • $column_name:
  • $choices:
  • $options:
  • $html_options:

Info

Method time_zone_options_for_select (line 316)

void time_zone_options_for_select( [ $selected = null], [ $priority_zones = array()], [ $model = 'AkTimeZone'])

Returns a string of option tags for pretty much any time zone in the

world. Supply a TimeZone name as +selected+ to have it marked as the selected option tag. You can also supply an array of TimeZones as +$priority_zones+, so that they will be listed above the rest of the (long) list.

The +selected+ parameter must be either +null+, or a string that names a TimeZone.

By default, +model+ is an AkTimeZone instance. The only requirement is that the +model+ parameter be an object that responds to #all, and returns an object with a toString() method and the TimeZone name provided by a 'name' attribute

For a list of supported timezones see: http://www.php.net/manual/en/timezones.php

NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.

Parameters

  • $selected:
  • $priority_zones:
  • $model:

Info

Method time_zone_select (line 119)

void time_zone_select( $object_name, $column_name, [ $priority_zones = array()], [ $options = array()], [ $html_options = array()])

Overridden in child classes as:

AkFormOptionsHelperBuilder::time_zone_select()

Return select and option tags for the given object and column_name, using #time_zone_options_for_select to generate the list of option tags.

In addition to the <tt>include_blank</tt> option documented above, this method also supports a <tt>model</tt> option, which defaults to TimeZone. This may be used by users to specify a different time zone model object. (See #time_zone_options_for_select for more information.)

Parameters

  • $object_name:
  • $column_name:
  • $priority_zones:
  • $options:
  • $html_options:

Info

Inherited Variables

Inherited Class Variable Summary

Inherited From Class AkActionViewHelper

AkActionViewHelper::$locales_namespace -

Inherited Methods

Inherited Method Summary

Inherited From Class AkActionViewHelper

AkActionViewHelper::AkActionViewHelper() -

AkActionViewHelper::addObject() -

AkActionViewHelper::getObject() -

AkActionViewHelper::setController() -

AkActionViewHelper::t() -



Documentation generated on Sat, 20 Oct 2007 00:23:24 +0200 by phpDocumentor 1.3.2