本文整理汇总了PHP中Dropdown::setSelected方法的典型用法代码示例。如果您正苦于以下问题:PHP Dropdown::setSelected方法的具体用法?PHP Dropdown::setSelected怎么用?PHP Dropdown::setSelected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dropdown
的用法示例。
在下文中一共展示了Dropdown::setSelected方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createDropdowns
/**
* create the dropdowns based on the previously set query or result array
* @throws \Exception
*/
protected function createDropdowns()
{
if (empty($this->data)) {
throw new \Exception('Error creating dropdowns, because there are no results to create dropdowns from.');
}
// the separator we use to glue the values of the different columns together to ensure uniqueness
$separator = '_';
// collect all values with their parent value into $options
$options = array();
foreach ($this->data as $row) {
$class = null;
foreach ($row as $colname => $value) {
// we store $class . $separator . $value instead of just $val, because it is possible that different level1's have same level2's
// and by collecting this way, they will not get overwritten
// Example: [ADSL2+][1. Geen mening] and [Fiber][1. Geen mening]
$title = $class . $separator . $value;
$options[$colname][$title] = array('value' => $value, 'label' => $value, 'class' => $class);
$class = $title;
// for the next column
}
}
$selected = $this->getSelected();
foreach ($options as $ddName => $ddOptionsAttributes) {
// create the dropdown
$dropdown = new Dropdown($ddName);
$dropdown->setLabel(initcap($ddName));
$dropdown->prependOption('', '-- all --');
$dropdown->appendOptionClass('');
// also add dummy values here
$dropdown->appendOptionTitle('');
// create the options with class and title
foreach ($ddOptionsAttributes as $title => $attributes) {
// add as option if label is not empty
if (!empty($attributes['label'])) {
$dropdown->appendOption($attributes['value'], $attributes['label']);
// replace spaces and other invalid class characters with underscores
// based on the class we search for parent options with title equals that class, so title needs the same replacements
$dropdown->appendOptionClass($this->toValidHtmlId($attributes['class'], '_'));
$dropdown->appendOptionTitle($this->toValidHtmlId($title, '_'));
}
}
// set the selected value
if (is_array($selected) && sizeof($selected)) {
$dropdown->setSelected(array_shift($selected));
}
// add to array of dropdowns
$this->dropdowns[] = $dropdown;
}
// refresh the posted values
if ($this->isPosted()) {
$this->setPosted();
}
}