本文整理汇总了PHP中Zend\Form\ElementInterface::getYearElement方法的典型用法代码示例。如果您正苦于以下问题:PHP ElementInterface::getYearElement方法的具体用法?PHP ElementInterface::getYearElement怎么用?PHP ElementInterface::getYearElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\ElementInterface
的用法示例。
在下文中一共展示了ElementInterface::getYearElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Render a date element that is composed of six selects
*
* @param ElementInterface $element
* @throws \Zend\Form\Exception\InvalidArgumentException
* @throws \Zend\Form\Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
if (!$element instanceof DateTimeSelectElement) {
throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\DateTimeSelect', __METHOD__));
}
$name = $element->getName();
if ($name === null || $name === '') {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$shouldRenderDelimiters = $element->shouldRenderDelimiters();
$selectHelper = $this->getSelectElementHelper();
$pattern = $this->parsePattern($shouldRenderDelimiters);
$daysOptions = $this->getDaysOptions($pattern['day']);
$monthsOptions = $this->getMonthsOptions($pattern['month']);
$yearOptions = $this->getYearsOptions($element->getMinYear(), $element->getMaxYear());
$hourOptions = $this->getHoursOptions($pattern['hour']);
$minuteOptions = $this->getMinutesOptions($pattern['minute']);
$secondOptions = $this->getSecondsOptions($pattern['second']);
$dayElement = $element->getDayElement()->setValueOptions($daysOptions);
$monthElement = $element->getMonthElement()->setValueOptions($monthsOptions);
$yearElement = $element->getYearElement()->setValueOptions($yearOptions);
$hourElement = $element->getHourElement()->setValueOptions($hourOptions);
$minuteElement = $element->getMinuteElement()->setValueOptions($minuteOptions);
$secondElement = $element->getSecondElement()->setValueOptions($secondOptions);
if ($element->shouldCreateEmptyOption()) {
$dayElement->setEmptyOption('');
$yearElement->setEmptyOption('');
$monthElement->setEmptyOption('');
$hourElement->setEmptyOption('');
$minuteElement->setEmptyOption('');
$secondElement->setEmptyOption('');
}
$data = array();
$data[$pattern['day']] = $selectHelper->render($dayElement);
$data[$pattern['month']] = $selectHelper->render($monthElement);
$data[$pattern['year']] = $selectHelper->render($yearElement);
$data[$pattern['hour']] = $selectHelper->render($hourElement);
$data[$pattern['minute']] = $selectHelper->render($minuteElement);
if ($element->shouldShowSeconds()) {
$data[$pattern['second']] = $selectHelper->render($secondElement);
} else {
unset($pattern['second']);
if ($shouldRenderDelimiters) {
unset($pattern[4]);
}
}
$markup = '';
foreach ($pattern as $key => $value) {
// Delimiter
if (is_numeric($key)) {
$markup .= $value;
} else {
$markup .= $data[$value];
}
}
$markup = trim($markup);
return $markup;
}
示例2: render
/**
* Render a month element that is composed of two selects
*
* @param \Zend\Form\ElementInterface $element
* @throws \Zend\Form\Exception\InvalidArgumentException
* @throws \Zend\Form\Exception\DomainException
* @return string
*/
public function render(ElementInterface $element)
{
if (!$element instanceof MonthSelectElement) {
throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\MonthSelect', __METHOD__));
}
$name = $element->getName();
if ($name === null || $name === '') {
throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__));
}
$selectHelper = $this->getSelectElementHelper();
$pattern = $this->parsePattern($element->shouldRenderDelimiters());
// The pattern always contains "day" part and the first separator, so we have to remove it
unset($pattern['day']);
unset($pattern[0]);
$monthsOptions = $this->getMonthsOptions($pattern['month']);
$yearOptions = $this->getYearsOptions($element->getMinYear(), $element->getMaxYear());
$monthElement = $element->getMonthElement()->setValueOptions($monthsOptions);
$yearElement = $element->getYearElement()->setValueOptions($yearOptions);
if ($element->shouldCreateEmptyOption()) {
$monthElement->setEmptyOption('');
$yearElement->setEmptyOption('');
}
$data = array();
$data[$pattern['month']] = $selectHelper->render($monthElement);
$data[$pattern['year']] = $selectHelper->render($yearElement);
$markup = '';
foreach ($pattern as $key => $value) {
// Delimiter
if (is_numeric($key)) {
$markup .= $value;
} else {
$markup .= $data[$value];
}
}
return $markup;
}
示例3: render
/**
* {@inheritDoc}
*/
public function render(ElementInterface $element)
{
$dateFormat = $element->getOption('date_format');
if ($dateFormat) {
$this->setDateType($dateFormat);
}
//$name = $element->getName();
$selectHelper = $this->getSelectElementHelper();
$pattern = $this->parsePattern($element->shouldRenderDelimiters());
$daysOptions = $this->getDaysOptions($pattern['day']);
$monthsOptions = $this->getMonthsOptions($pattern['month']);
$yearOptions = $this->getYearsOptions($element->getMinYear(), $element->getMaxYear());
$dayElement = $element->getDayElement()->setValueOptions($daysOptions);
$monthElement = $element->getMonthElement()->setValueOptions($monthsOptions);
$yearElement = $element->getYearElement()->setValueOptions($yearOptions);
if ($element->shouldCreateEmptyOption()) {
$dayElement->setEmptyOption(__('Day'));
$yearElement->setEmptyOption(__('Year'));
$monthElement->setEmptyOption(__('Month'));
}
$data = array();
$data[$pattern['day']] = $selectHelper->render($dayElement);
$data[$pattern['month']] = $selectHelper->render($monthElement);
$data[$pattern['year']] = $selectHelper->render($yearElement);
$markup = '';
foreach ($pattern as $key => $value) {
// Delimiter
if (is_numeric($key)) {
$markup .= $value;
} else {
$markup .= $data[$value];
}
}
return $markup;
//return parent::render($element);
}