本文整理汇总了PHP中Zend\Form\ElementInterface::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP ElementInterface::getAttribute方法的具体用法?PHP ElementInterface::getAttribute怎么用?PHP ElementInterface::getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\ElementInterface
的用法示例。
在下文中一共展示了ElementInterface::getAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Render a form <input> element from the provided $element
*
* @param ElementInterface $element Zend Form Element
*
* @throws Exception\InvalidArgumentException
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
if (!$element instanceof CheckboxElement) {
throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Checkbox', __METHOD__));
}
$name = $element->getName();
if (empty($name) && $name !== 0) {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$attributes = $element->getAttributes();
$attributes['name'] = $name;
$attributes['type'] = $this->getInputType();
$attributes['value'] = $element->getCheckedValue();
$closingBracket = $this->getInlineClosingBracket();
if ($element->isChecked()) {
$attributes['checked'] = 'checked';
}
if ($element->getAttribute('class') != 'input-checkbox') {
$rendered = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket);
} else {
if ($element->getAttribute('id') == '') {
$element->setAttribute('id', 'checkbox-' . uniqid());
}
unset($attributes['class']);
$rendered = sprintf('<span class="input-checkbox"><input %s%s<label for="%s"></label></span>', $this->createAttributesString($attributes), $closingBracket, $element->getAttribute('id'));
}
return $rendered;
}
示例2: render
public function render(ElementInterface $element)
{
/* just a reminder. the types are:
checkbox, color, date, datetime, datetime-local, email, file, hidden
image, month, multi_checkbox, number, password, radio, range, reset
search, select, submit, tel, text, textarea, time, url, week
*/
$labelHelper = $this->getLabelHelper();
$escapeHelper = $this->getEscapeHtmlHelper();
$elementHelper = $this->getElementHelper();
$elementErrorHelper = $this->getElementErrorHelper();
$descriptionHelper = $this->getDescriptionHelper();
$groupWrapper = $groupWrapper ?: $this->groupWrapper;
$controlWrapper = $controlWrapper ?: $this->controlWrapper;
$id = $element->getAttribute('id') ?: $element->getAttribute('name');
$html = "";
$label = $element->getAttribute('label');
if ($label) {
$html .= $labelHelper->openTag(array('for' => $id, 'class' => 'control-label'));
// todo allow for not escaping the label
$html .= $escapeHelper($label);
$html .= $labelHelper->closeTag();
}
$html .= sprintf($controlWrapper, $id, $elementHelper->render($element), $descriptionHelper->render($element), $elementErrorHelper->render($element));
$addtClass = $element->getMessages() ? ' error' : '';
echo $element->getLabel();
die;
$output .= parent::render($element);
return $output;
}
示例3: closeTag
/**
* Return a closing label tag
*
* @return string
*/
public function closeTag()
{
$result = '</label>';
if ($this->element->hasAttribute('required') && $this->element->getAttribute('required')) {
$result = sprintf('<span class="required-mark">*</span> %s', $result);
}
return $result;
}
示例4: render
/**
* @param ElementInterface $element
*
* @return string
*/
public function render(ElementInterface $element)
{
$captcha = $element->getCaptcha();
if ($captcha === null || !$captcha instanceof AdapterInterface) {
throw new Exception\DomainException(sprintf('%s requires that the element has a "captcha" attribute implementing Zend\\Captcha\\AdapterInterface', __METHOD__));
}
$name = $element->getName();
$id = $element->getAttribute('id') ? $element->getAttribute('id') : $name;
$captchaPattern = '<div %s></div>';
$captchaAttributes = $this->createAttributesString(array('class' => 'g-recaptcha ' . $element->getAttribute('class'), 'data-sitekey' => $captcha->getSiteKey(), 'data-theme' => $captcha->getTheme(), 'data-type' => $captcha->getType(), 'data-callback' => $captcha->getCallback()));
$captchaElement = sprintf($captchaPattern, $captchaAttributes);
$input = $this->renderHiddenInput($id, $name);
$js = $this->renderJsCallback($captcha->getCallback(), $id);
return $captchaElement . $input . $js;
}
示例5: render
public function render(ElementInterface $element)
{
if (in_array($element->getAttribute('type'), array('html'))) {
return $element->getValue();
}
return parent::render($element);
}
示例6: render
public function render(ElementInterface $element)
{
$element->setAttribute('class', $element->getAttribute('class') . " btn");
$input = parent::render($element);
$options = $element->getOptions();
if (!empty($options['as-group'])) {
$col_left_width = 'sm-6';
$col_right_width = 'sm-6';
$button_column = 'left';
if (!empty($options['col-left-width'])) {
$col_left_width = $options['col-left-width'];
}
if (!empty($options['col-right-width'])) {
$col_right_width = $options['col-right-width'];
}
if (!empty($options['button-column'])) {
$button_column = $options['button-column'];
}
$colFormat = '<div class="col-%s">%s</div><div class="col-%s">%s</div>';
$buttonFormat = '<div class="btn-group btn-group-justified"><div class="btn-group">%s</div></div>';
$inputContainer = sprintf($buttonFormat, $input);
$leftColumn = $inputContainer;
$rightColumn = '';
if ($button_column != 'left') {
$leftColumn = '';
$rightColumn = $inputContainer;
}
$input = sprintf($colFormat, $col_left_width, $leftColumn, $col_right_width, $rightColumn);
}
return $input;
}
示例7: render
public function render(ElementInterface $element = null)
{
if ($element->getMessages()) {
$element->setAttribute('class', 'error ' . $element->getAttribute('class'));
}
return parent::render($element);
}
示例8: init
public function init(ElementInterface $element)
{
$this->formElement = $element;
if ($element->hasAttribute('template')) {
$this->template = $element->getAttribute('template');
}
}
示例9: render
/**
* Override
*
* Render the captcha
*
* @param ElementInterface $element
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
//we could also set the separator here to break between the inputs and the image.
//$this->setSeparator('')
$captcha = $element->getCaptcha();
if ($captcha === null || !$captcha instanceof CaptchaAdapter) {
throw new DomainException(sprintf('%s requires that the element has a "captcha" attribute of type Recruitment\\Model\\CaptchaImage;
none found', __METHOD__));
}
$captcha->generate();
$imgAttributes = array('width' => $captcha->getWidth(), 'height' => $captcha->getHeight(), 'alt' => $captcha->getImgAlt(), 'src' => $captcha->getImgUrl() . $captcha->getId() . $captcha->getSuffix(), 'class' => 'thumbnail center-block');
if ($element->hasAttribute('id')) {
$imgAttributes['id'] = $element->getAttribute('id') . '-image';
}
$closingBracket = $this->getInlineClosingBracket();
$img = sprintf('<img %s%s ', $this->createAttributesString($imgAttributes), $closingBracket);
$position = $this->getCaptchaPosition();
$separator = $this->getSeparator();
$captchaInput = $this->renderCaptchaInputs($element);
$pattern = '%s' . '<div class="input-group">' . '%s%s' . '<span class="input-group-btn">' . '<button id="' . $element->getAttribute('id') . '-refresh' . '" class="btn btn-default" type="button">' . '<i class="ion-loop"></i>' . '</button>' . '</span>' . '</div>';
if ($position == self::CAPTCHA_PREPEND) {
return sprintf($pattern, $captchaInput, $separator, $img);
}
return sprintf($pattern, $img, $separator, $captchaInput);
}
示例10: render
/**
* {@inheritDoc}
*/
public function render(ElementInterface $element)
{
$captcha = $element->getCaptcha();
if ($captcha === null || !$captcha instanceof CaptchaAdapter) {
throw new Exception\DomainException(sprintf('%s requires that the element has a "captcha" attribute' . ' of type Zend\\Captcha\\Image; none found', __METHOD__));
}
// Generates ID, but NOT word and image
$captcha->generate();
// Generates URL to access image, and image won't be generated until the URL is accessed
$imgSrc = $captcha->getImgUrl() . '?id=' . $captcha->getId();
$imgAttributes = array('width' => $captcha->getWidth(), 'height' => $captcha->getHeight(), 'src' => $imgSrc, 'onclick' => sprintf('this.src=\'%s&refresh=\'+Math.random()', $imgSrc), 'style' => 'cursor: pointer; vertical-align: middle;', 'alt' => __('CAPTCHA image'), 'title' => __('Click to refresh CAPTCHA'));
if ($element->hasAttribute('id')) {
$imgAttributes['id'] = $element->getAttribute('id') . '-image';
} else {
$imgAttributes['id'] = $captcha->getId() . '-image';
}
$closingBracket = $this->getInlineClosingBracket();
$img = sprintf('<img %s%s', $this->createAttributesString($imgAttributes), $closingBracket);
$position = $this->getCaptchaPosition();
$separator = $this->getSeparator();
$captchaInput = $this->renderCaptchaInputs($element);
$pattern = '%s%s%s';
if ($position == static::CAPTCHA_PREPEND) {
return sprintf($pattern, $captchaInput, $separator, $img);
}
return sprintf($pattern, $img, $separator, $captchaInput);
}
示例11: render
/**
* Render a form <input> element from the provided $element
*
* @param ElementInterface $element
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
$src = $element->getAttribute('src');
if (empty($src)) {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned src; none discovered', __METHOD__));
}
return parent::render($element);
}
示例12: render
public function render(ElementInterface $element)
{
if ($element->hasAttribute('data-placeholder')) {
$placeholder = $element->getAttribute('data-placeholder');
$placeholder = $this->getTranslator()->translate($placeholder, $this->getTranslatorTextDomain());
$element->setAttribute('data-placeholder', $placeholder);
}
return parent::render($element);
}
示例13: render
/**
* Render a form <input> element from the provided $element
*
* @param ElementInterface $element
* @throws Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
$class = $element->getAttribute('class');
if (in_array($this->getType($element), array('submit', 'reset', 'button'))) {
$class = 'btn' . (empty($class) ? '' : ' ' . $class);
}
$element->setAttribute('class', $class);
return parent::render($element);
}
示例14: prepareElementBeforeRendering
/**
* Prepares the element prior to rendering
* @param \Zend\Form\ElementInterface $element
* @param string $formType
* @param array $displayOptions
* @return void
*/
protected function prepareElementBeforeRendering(ElementInterface $element, $formType, array $displayOptions)
{
if (array_key_exists('class', $displayOptions)) {
$class = $element->getAttribute('class');
$class = $this->genUtil->addWords($displayOptions['class'], $class);
$escapeHtmlAttrHelper = $this->getEscapeHtmlAttrHelper();
$class = $this->genUtil->escapeWords($class, $escapeHtmlAttrHelper);
$element->setAttribute('class', $class);
}
$this->formUtil->addIdAttributeIfMissing($element);
}
示例15: addScripts
public function addScripts(ElementInterface $oElement)
{
$view = $this->getView();
$id = $oElement->getAttribute('id');
$inlinejs = sprintf(self::$inlineSriptFormat, $id);
$script = $view->inlineScript();
$headScript = $view->headScript();
$script->appendScript($inlinejs, 'text/javascript', array('noescape' => true));
// Disable CDATA comments
$headScript->appendFile($view->basePath('js/bootstrap-slider.min.js'));
}