baser/views/helpers/form_ex.php
/**
 * Returns an array of formatted OPTION/OPTGROUP elements
 * 
 * @return array
 * @access private
 */
Returns an array of formatted OPTION/OPTGROUP elements

@return array
@access private
Returns an array of formatted OPTION / OPTGROUP elements @return array @access private
function __selectOptions($elements = array(), $selected = null, $parents = array(), $showParents = null, $attributes = array()) {
		$select = array();
		$attributes = array_merge(array('escape' => true, 'style' => null), $attributes);
		$selectedIsEmpty = ($selected === '' || $selected === null);
		$selectedIsArray = is_array($selected);
		foreach ($elements as $name => $title) {
			$htmlOptions = array();
			if (is_array($title) && (!isset($title['name']) || !isset($title['value']))) {
				if (!empty($name)) {
					if ($attributes['style'] === 'checkbox') {
						$select[] = $this->Html->tags['fieldsetend'];
					} else {
						$select[] = $this->Html->tags['optiongroupend'];
					}
					$parents[] = $name;
				}
				$select = array_merge($select, $this->__selectOptions(
						$title, $selected, $parents, $showParents, $attributes
				));
				if (!empty($name)) {
					if ($attributes['style'] === 'checkbox') {
						$select[] = sprintf($this->Html->tags['fieldsetstart'], $name);
					} else {
						$select[] = sprintf($this->Html->tags['optiongroup'], $name, '');
					}
				}
				$name = null;
			} elseif (is_array($title)) {
				$htmlOptions = $title;
				$name = $title['value'];
				$title = $title['name'];
				unset($htmlOptions['name'], $htmlOptions['value']);
			}
			if ($name !== null) {
				if ((!$selectedIsEmpty && $selected == $name) || ($selectedIsArray && in_array($name, $selected))) {
					if ($attributes['style'] === 'checkbox') {
						$htmlOptions['checked'] = true;
					} else {
						$htmlOptions['selected'] = 'selected';
					}
				}
				if ($showParents || (!in_array($title, $parents))) {
					$title = ($attributes['escape']) ? h($title) : $title;
					if ($attributes['style'] === 'checkbox') {
						$htmlOptions['value'] = $name;
						$tagName = Inflector::camelize(
								$this->model() . '_' . $this->field().'_'.Inflector::underscore($name)
						);
						$htmlOptions['id'] = $tagName;
						$label = array('for' => $tagName);
						if (isset($htmlOptions['checked']) && $htmlOptions['checked'] === true) {
							$label['class'] = 'selected';
						}
						list($name) = array_values($this->__name());
						if (empty($attributes['class'])) {
							$attributes['class'] = 'checkbox';
						}
						$label = $this->label(null, $title, $label);
						$item = sprintf(
								$this->Html->tags['checkboxmultiple'], $name,
								$this->Html->_parseAttributes($htmlOptions)
						);
						if(isset($attributes['div']) && $attributes['div']===false) {
							$select[] = $item.$label;
						}else {
							$select[] = $this->Html->div($attributes['class'], $item . $label);
						}
					} else {
						$select[] = sprintf(
								$this->Html->tags['selectoption'],
								$name, $this->Html->_parseAttributes($htmlOptions), $title
						);
					}
				}
			}
		}
		return array_reverse($select, true);
	}
function __selectOptions ( $ elements = array ( ) , $ selected = null , $ parents = array ( ) , $ showParents = null , $ attributes = array ( ) ) { $ select = array ( ) ; $ attributes = array_merge ( array ( 'escape' => true , 'style' => null ) , $ attributes ) ; $ selectedIsEmpty = ( $ selected === '' || $ selected === null ) ; $ selectedIsArray = is_array ( $ selected ) ; foreach ( $ elements as $ name => $ title ) { $ htmlOptions = array ( ) ; if ( is_array ( $ title ) && ( ! isset ( $ title [ 'name' ] ) || ! isset ( $ title [ 'value' ] ) ) ) { if ( ! empty ( $ name ) ) { if ( $ attributes [ 'style' ] === 'checkbox' ) { $ select [ ] = $ this -> Html -> tags [ 'fieldsetend' ] ; } else { $ select [ ] = $ this -> Html -> tags [ 'optiongroupend' ] ; } $ parents [ ] = $ name ; } $ select = array_merge ( $ select , $ this -> __selectOptions ( $ title , $ selected , $ parents , $ showParents , $ attributes ) ) ; if ( ! empty ( $ name ) ) { if ( $ attributes [ 'style' ] === 'checkbox' ) { $ select [ ] = sprintf ( $ this -> Html -> tags [ 'fieldsetstart' ] , $ name ) ; } else { $ select [ ] = sprintf ( $ this -> Html -> tags [ 'optiongroup' ] , $ name , '' ) ; } } $ name = null ; } elseif ( is_array ( $ title ) ) { $ htmlOptions = $ title ; $ name = $ title [ 'value' ] ; $ title = $ title [ 'name' ] ; unset ( $ htmlOptions [ 'name' ] , $ htmlOptions [ 'value' ] ) ; } if ( $ name !== null ) { if ( ( ! $ selectedIsEmpty && $ selected == $ name ) || ( $ selectedIsArray && in_array ( $ name , $ selected ) ) ) { if ( $ attributes [ 'style' ] === 'checkbox' ) { $ htmlOptions [ 'checked' ] = true ; } else { $ htmlOptions [ 'selected' ] = 'selected' ; } } if ( $ showParents || ( ! in_array ( $ title , $ parents ) ) ) { $ title = ( $ attributes [ 'escape' ] ) ? h ( $ title ) : $ title ; if ( $ attributes [ 'style' ] === 'checkbox' ) { $ htmlOptions [ 'value' ] = $ name ; $ tagName = Inflector :: camelize ( $ this -> model ( ) . '_' . $ this -> field ( ) . '_' . Inflector :: underscore ( $ name ) ) ; $ htmlOptions [ 'id' ] = $ tagName ; $ label = array ( 'for' => $ tagName ) ; if ( isset ( $ htmlOptions [ 'checked' ] ) && $ htmlOptions [ 'checked' ] === true ) { $ label [ 'class' ] = 'selected' ; } list ( $ name ) = array_values ( $ this -> __name ( ) ) ; if ( empty ( $ attributes [ 'class' ] ) ) { $ attributes [ 'class' ] = 'checkbox' ; } $ label = $ this -> label ( null , $ title , $ label ) ; $ item = sprintf ( $ this -> Html -> tags [ 'checkboxmultiple' ] , $ name , $ this -> Html -> _parseAttributes ( $ htmlOptions ) ) ; if ( isset ( $ attributes [ 'div' ] ) && $ attributes [ 'div' ] === false ) { $ select [ ] = $ item . $ label ; } else { $ select [ ] = $ this -> Html -> div ( $ attributes [ 'class' ] , $ item . $ label ) ; } } else { $ select [ ] = sprintf ( $ this -> Html -> tags [ 'selectoption' ] , $ name , $ this -> Html -> _parseAttributes ( $ htmlOptions ) , $ title ) ; } } } } return array_reverse ( $ select , true ) ; }
Returns an array of formatted OPTION/OPTGROUP elements
Returns an array of formatted OPTION / OPTGROUP elements
// checkboxのdivを外せるオプションを追加