本文整理汇总了PHP中Zend\Form\ElementInterface::setMessages方法的典型用法代码示例。如果您正苦于以下问题:PHP ElementInterface::setMessages方法的具体用法?PHP ElementInterface::setMessages怎么用?PHP ElementInterface::setMessages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\ElementInterface
的用法示例。
在下文中一共展示了ElementInterface::setMessages方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* {@inheritDoc}
*/
public function render(ElementInterface $element, array $attributes = [])
{
$markup = '';
$renderer = $this->getView();
if (!method_exists($renderer, 'plugin')) {
return $markup;
}
/* @var $flashMessenger \Zend\View\Helper\FlashMessenger */
$flashMessenger = $renderer->plugin('flashmessenger');
if ($flashMessenger->hasCurrentMessages() || $element->getMessages()) {
$formName = $element->getName();
foreach ($this->classMessages as $namespace => $class) {
$attribs = $attributes;
if ($namespace === PluginFlashMessenger::NAMESPACE_ERROR) {
$flashMessenger->setTranslatorTextDomain($this->getTranslatorTextDomain());
if (!$this->getMessageOpenFormat()) {
$this->setMessageOpenFormat($flashMessenger->getMessageOpenFormat());
}
if (!$this->getMessageSeparatorString()) {
$this->setMessageSeparatorString($flashMessenger->getMessageSeparatorString());
}
if (!$this->getMessageCloseString()) {
$this->setMessageCloseString($flashMessenger->getMessageCloseString());
}
if ($flashMessenger->hasCurrentMessages() && ($messages = $flashMessenger->getCurrentMessagesFromNamespace("{$formName}-{$namespace}"))) {
$element->setMessages(array_merge($element->getMessages(), $messages));
}
if (isset($attribs['class'])) {
$attribs['class'] .= ' ' . $class;
} else {
$attribs['class'] = $class;
}
$markup .= parent::render($element, $attribs);
} elseif ($flashMessenger->hasCurrentMessages()) {
if (isset($attribs['class'])) {
$class = array_merge((array) $attribs['class'], (array) $class);
}
$markup .= $flashMessenger->renderCurrent("{$formName}-{$namespace}", (array) $class);
}
}
}
return $markup;
}