Generator method used by `select()` to produce `<option />` and `<optgroup />` elements. Generally, this method should not need to be called directly, but through `select()`.

Parameters

  • array $list Either a flat key/value array of select menu options, or an array which contains key/value elements and/or elements where the keys are `<optgroup />` titles and the values are sub-arrays of key/value pairs representing nested `<option />` elements.
  • array $scope An array of options passed to the parent scope, including the currently selected value of the associated form element.

Returns

string Returns a string of `<option />` and (optionally) `<optgroup />` tags to be embedded in a select element.

Source

						protected function _selectOptions(array $list, array $scope) {
		$result = "";

		foreach ($list as $value => $title) {
			if (is_array($title)) {
				$label = $value;
				$options = array();

				$raw = $this->_selectOptions($title, $scope);
				$params = compact('label', 'options', 'raw');
				$result .= $this->_render('select', 'option-group', $params);
				continue;
			}
			$selected = (
				(is_array($scope['value']) && in_array($value, $scope['value'])) ||
				($scope['empty'] && empty($scope['value']) && $value === '') ||
				(is_scalar($scope['value']) && ((string) $scope['value'] === (string) $value))
			);
			$options = $selected ? array('selected' => true) : array();
			$params = compact('value', 'title', 'options');
			$result .= $this->_render('select', 'select-option',  $params);
		}
		return $result;
	}