6.5 Понимание и использование Zend Form Decorators. Создание и визуализация составных элементов | Participants
|
- Statistics
- Participants
- Translate into Russian
- Translation result
- 9% translated in draft.
If you do not want to register an account, you can sign in with OpenID.
Understanding and Using Zend Form Decorators. Creating and Rendering Composite Elements | 6.5 Понимание и использование Zend Form Decorators. Создание и визуализация составных элементов | |
In the last section, we had an example showing a "date of birth element": | В последнем разделе был приведен пример элемента "дата рождения" | |
01. <div class="element"> | ||
02. <?php echo $form->dateOfBirth->renderLabel() ?> | ||
03. <?php echo $this->formText('dateOfBirth[day]', '', array( | ||
04. 'size' => 2, 'maxlength' => 2)) ?> | ||
05. / | ||
06. <?php echo $this->formText('dateOfBirth[month]', '', array( | ||
07. 'size' => 2, 'maxlength' => 2)) ?> | ||
08. / | ||
09. <?php echo $this->formText('dateOfBirth[year]', '', array( | ||
10. 'size' => 4, 'maxlength' => 4)) ?> | ||
11. </div> | ||
How might you represent this element as a Zend_Form_Element? How might you write a decorator to render it? | Каким образом Вы можете представить этот элемент как Zend_Form_Element? Как вы напишете декоратор для его визуализации? | |
The Element | ||
The questions about how the element would work include: | ||
• How would you set and retrieve the value? | ||
• How would you validate the value? | ||
• Regardless, how would you then allow for discrete form inputs for the three segments (day, month, year)? | Так или иначе, как Вы тогда разрешите отдельные поля ввода для трех частей (число, месяц, год)? | |
The first two questions center around the form element itself: how would setValue() and getValue() work? There's actually another question implied by the question about the decorator: how would you retrieve the discrete date segments from the element and/or set them? | Первых два вопроса нацелены на сам элемент: как будут работать setValue() и getValue()? На самом деле здесь имеется ввиду вопрос о декораторе: как извлечь отдельные части элемента и/или установить их? | |
The solution is to override the setValue() method of your element to provide some custom logic. In this particular case, our element should have three discrete behaviors: | Решение заключается в переопределении метода setValue() Вашего элемента для применения собственной логики. В этом особенном случае наш элемент должен иметь три отдельных поведения: | |
• If an integer timestamp is provided, it should be used to determine and store the day, month, and year. | ||
• If a textual string is provided, it should be cast to a timestamp, and then that value used to determine and store the day, month, and year. | ||
• If an array containing keys for date, month, and year is provided, those values should be stored. | ||
Internally, the day, month, and year will be stored discretely. When the value of the element is retrieved, it will be done so in a normalized string format. We'll override getValue() as well to assemble the discrete date segments into a final string. |
