At runtime, a FieldtypeDynamicSelects field (a DynamicSelects object) returns a number of properties. The most important for frontend use would be the values of each dropdown. Examples are shown below.
Please note that below, columnName refers to the name of a column in a dynamic select's database table. For instance, assuming a Dynamic Selects field named dynamic on a given $page, the following properties would be returned.
$ds = $page->dynamic; echo $ds->countries;// would output UK echo $ds->cities;// London echo $ds->attractions;// Big Ben // OR echo $page->dynamic->countries;// UK echo $page->dynamic->cities;// London echo $page->dynamic->attractions;// Big Ben
From the above examples we can see that the properties returned have their values converted from the raw ID to user-friendly values. Also note that the ->countries, ->cities and ->attractions are subfields of the field (property) dynamic.
Additional properties returned by the field follow the format columnName + a pre-defined suffix. For instance, columnNameID whereby ID would be ID of the saved value that is stored in the database.
echo $ds->countriesID;// would output 1234 which in our example is the ID of the page UK echo $ds->citiesID;// outputs ID of London echo $ds->attractionsID;// outputs the ID of the selected page in the pagefield 'Attractions', i.e. 'Big Ben'. // Please note that for values from pagefields, the ID of the page in the pagefield is stored. // For other fields, the ID of the field itself is stored // e.g. 45 could be the ID of an integer field if we had a column $ds->price
echo $ds->countriesTriggerID;// outputs 0 since this is the first dropdown echo $ds->citiesTriggerID;// outputs 1234 => the ID of UK echo $ds->attractionsTriggerID;// outputs the ID of London echo $ds->countriesTrigger;// outputs null as this is the first dropdown echo $ds->citiesTrigger;// outputs UK echo $ds->attractionsTrigger;// outputs London
echo $ds->countriesRelationshipID;// outputs 0 since this is the first dropdown echo $ds->citiesRelationshipID;// outputs 1, denoting a 'Child' relationship echo $ds->attractionsRelationshipID;// outputs 6, denoting a 'Value' relationship echo $ds->countriesRelationship;// outputs None since this is the first dropdown echo $ds->citiesRelationship;// outputs Child echo $ds->attractionsRelationship;// outputs Value
Data Source Properties
echo $ds->countriesSourceID;// outputs 0 since this is the first dropdown echo $ds->citiesSourceID;// outputs 1, the ID of the field Title echo $ds->attractionsSourceID;// outputs 114, the ID of the pagefield Attractions echo $ds->countriesSource;// outputs Initial since this is the first dropdown echo $ds->citiesSource;// outputs title echo $ds->attractionsSource;// outputs attractions (a pagefield)
Page ID Property
For Varies and User: Varies data sources, we also have a columnNamePageID property. This will return the ID of the page from which the value of the saved field ID should be retrieved. This is really only important for internal use in InputfieldDynamicSelects.
Extra Data Property
$ds->extraData;// property returns an array
This is only useful for internal use to match selected/saved values in the dropdowns in InputfieldDynamicSelects in cases whereby multiple values could be selected from one field on one page whereby the values lack unique IDs. For instance, multiple image fields or multiple file fields.
Column Names and Column Labels Properties
Mainly important for internal use. These properties return arrays of all the column names and column labels defined in the given Dynamic Selects field. The properties are:
$ds->columnNames;// would output array('countries', 'cities', 'attractions'); $ds->columnLabels;// would return array('Countries', 'Cities', 'Attractions');
Please also note that field has a toString() method that outputs a HTML table of saved values if the field is directly echo'ed in a template file.
echo $page->dynamic;// this would output a HTML table