本文整理汇总了PHP中FormHelper::_selectOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP FormHelper::_selectOptions方法的具体用法?PHP FormHelper::_selectOptions怎么用?PHP FormHelper::_selectOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormHelper
的用法示例。
在下文中一共展示了FormHelper::_selectOptions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _selectOptions
/**
* Overwrite FormHelper::_selectOptions()
*
* - If $attributes['style'] is `<input type="checkbox">` then replace `<label>` position
* - Returns an array of formatted OPTION/OPTGROUP elements
*
* @param array $elements Elements to format.
* @param array $parents Parents for OPTGROUP.
* @param bool $showParents Whether to show parents.
* @param array $attributes HTML attributes.
* @return array
*/
protected function _selectOptions($elements = array(), $parents = array(), $showParents = null, $attributes = array())
{
$selectOptions = parent::_selectOptions($elements, $parents, $showParents, $attributes);
if ($attributes['style'] === 'checkbox') {
foreach ($selectOptions as $key => $option) {
$option = preg_replace('/<div.*?>/', '', $option);
$option = preg_replace('/<\\/div>/', '', $option);
if (preg_match('/>(<label.*?>)/', $option, $match)) {
$class = $attributes['class'];
if (preg_match('/.* class="(.*)".*/', $match[1], $classMatch)) {
$class = $classMatch[1] . ' ' . $attributes['class'];
$match[1] = str_replace(' class="' . $classMatch[1] . '"', '', $match[1]);
}
$option = $match[1] . preg_replace('/<label.*?>/', ' ', $option);
$option = preg_replace('/(<label.*?)(>)/', '$1 class="' . $class . '"$2', $option);
}
$selectOptions[$key] = $option;
}
}
return $selectOptions;
}
示例2: _selectOptions
/**
* Overwrite FormHelper::_selectOptions()
* Remove form-control if added here as it would only be added to the div.
*
* @param array $elements
* @param array $parents
* @param bool $showParents
* @param array $attributes
* @return array
*/
protected function _selectOptions($elements = array(), $parents = array(), $showParents = null, $attributes = array())
{
if ($attributes['style'] === 'checkbox') {
if (!empty($attributes['class']) && $attributes['class'] === array('form-control')) {
unset($attributes['class']);
}
}
$selectOptions = parent::_selectOptions($elements, $parents, $showParents, $attributes);
return $selectOptions;
}