本文整理汇总了PHP中Zend_Form_Element::setOrder方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form_Element::setOrder方法的具体用法?PHP Zend_Form_Element::setOrder怎么用?PHP Zend_Form_Element::setOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form_Element
的用法示例。
在下文中一共展示了Zend_Form_Element::setOrder方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: insertBefore
/**
* Inserts $newElement right before $reference.
*
* @param Zend_Form $form
* @param Zend_Form_Element $reference
* @param Zend_Form_Element $newElement
*/
protected function insertBefore(Zend_Form $form, Zend_Form_Element $reference, Zend_Form_Element $newElement)
{
/* @var $orderedElements array(Zend_Form_Element|Zend_Form|Zend_Form_DisplayGroup) */
$orderedElements = array_values(iterator_to_array($form));
// Ensure that each element has a numerical order value.
$this->assignOrderValues($orderedElements);
$buttonIndex = array_search($reference, $orderedElements, true);
$buttonOrder = $orderedElements[$buttonIndex]->getOrder();
if ($buttonIndex === 0) {
// Button is the first element, therefore no previous element
// whose order could be used for calculation exists.
// Choose a constant value which ensures that the calculated
// order value for the new element avoids re-ordering.
$previousElementOrder = $buttonOrder - 2;
} else {
$previousElementOrder = $orderedElements[$buttonIndex - 1]->getOrder();
}
// Try to assign an order value between previous element and button order value.
$newElementOrder = (int) round(($previousElementOrder + $buttonOrder) / 2);
$newElement->setOrder($newElementOrder);
// Insert $newElement at the position of the button.
array_splice($orderedElements, $buttonIndex, 0, array($newElement));
if ($newElementOrder === $buttonOrder) {
// Order values clash, therefore a re-ordering of the elements
// starting with the captcha is required.
$elementsFromCaptcha = array_slice($orderedElements, $buttonIndex);
$this->assignOrderValues($elementsFromCaptcha);
}
$this->reAssignElements($form, $orderedElements);
}