本文整理汇总了PHP中Zend_Form_Element::setOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form_Element::setOptions方法的具体用法?PHP Zend_Form_Element::setOptions怎么用?PHP Zend_Form_Element::setOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form_Element
的用法示例。
在下文中一共展示了Zend_Form_Element::setOptions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addElement
/**
* Add a new element
*
* $element may be either a string element type, or an object of type
* Zend_Form_Element. If a string element type is provided, $name must be
* provided, and $options may be optionally provided for configuring the
* element.
*
* If a Zend_Form_Element is provided, $name may be optionally provided,
* and any provided $options will be ignored.
*
* @param string|Zend_Form_Element $element
* @param string $name
* @param array|Zend_Config $options
* @throws Zend_Form_Exception on invalid element
* @return Zend_Form
*/
public function addElement($element, $name = null, $options = null)
{
if ($element instanceof Zend_Form_Element) {
// type string
$exploderesult = explode('_', $element->getType());
$type = lcfirst(trim(end($exploderesult)));
if (null !== $options && $options instanceof Zend_Config) {
$options = $options->toArray();
}
// Load default decorators
if (null === $options || !is_array($options)) {
$options = array();
//Class is maybe not properly transfered to this element. We'll add class if it exists here.
if ($element->class) {
$options['class'] = $element->class;
}
}
if (!array_key_exists('decorators', $options)) {
$decorators = $this->getDefaultDecoratorsByElementType($type);
if (!empty($decorators)) {
$options['decorators'] = $decorators;
}
}
// Elements type use 'form-control' class
$element_fc = array('text', 'password', 'dateTime', 'dateTimeLocal', 'date', 'month', 'time', 'week', 'number', 'email', 'url', 'search', 'tel', 'color', 'textarea', 'select', 'multiselect');
if (in_array($type, $element_fc)) {
if (null === $options) {
$options = array('class' => 'form-control');
} elseif (array_key_exists('class', $options)) {
if (!strstr($options['class'], 'form-control')) {
$options['class'] .= ' form-control';
$options['class'] = trim($options['class']);
}
} else {
$options['class'] = 'form-control';
}
}
$element->setOptions($options);
}
parent::addElement($element, $name, $options);
}