AkActionViewHelper | --FormOptionsHelper
Located in File: /AkActionView/helpers/form_options_helper.php
== 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>
Method collection_select (line 94)
Overridden in child classes as:
Method country_options_for_select (line 272)
NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
Method country_select (line 103)
Overridden in child classes as:
Method options_for_select (line 149)
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.
Method options_from_collection_for_select (line 185)
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.
Method option_groups_from_collection_for_select (line 237)
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.
Method select (line 85)
Overridden in child classes as:
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.
Method time_zone_options_for_select (line 316)
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.
Method time_zone_select (line 119)
Overridden in child classes as:
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.)
AkActionViewHelper::$locales_namespace -
AkActionViewHelper::AkActionViewHelper() -
AkActionViewHelper::addObject() -
AkActionViewHelper::getObject() -
AkActionViewHelper::setController() -
AkActionViewHelper::t() -