6.5 Понимание и использование Zend Form Decorators. Создание и визуализация составных элементов

Zend, “Understanding and Using Zend Form Decorators. Creating and Rendering Composite Elements”, public translation into Russian from English More about this translation.

See also 44 similar translations

Translate into another language.

Participants

victorgugo86 125 points
antdmi 1 no points
Join Translated.by to translate! If you already have a Translated.by account, please sign in.
If you do not want to register an account, you can sign in with OpenID.
Pages: ← previous Ctrl next next untranslated
1 2 3 4 5 6

Understanding and Using Zend Form Decorators. Creating and Rendering Composite Elements

6.5 Понимание и использование Zend Form Decorators. Создание и визуализация составных элементов

History of edits (Latest: antdmi 6 years, 5 months ago) §

In the last section, we had an example showing a "date of birth element":

В последнем разделе был приведен пример элемента "дата рождения"

History of edits (Latest: victorgugo86 7 years, 1 month ago) §

  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? Как вы напишете декоратор для его визуализации?

History of edits (Latest: victorgugo86 7 years, 1 month ago) §

The Element

Элемент

History of edits (Latest: victorgugo86 7 years, 1 month ago) §

The questions about how the element would work include:

Вопрос о том как элемент будет работать включает:

History of edits (Latest: victorgugo86 7 years, 1 month ago) §

    • How would you set and retrieve the value?

Как Вы установите и извлечете значение?

History of edits (Latest: victorgugo86 7 years, 1 month ago) §

    • How would you validate the value?

Каким образом Вы провалидируете значение?

History of edits (Latest: victorgugo86 7 years, 1 month ago) §

    • Regardless, how would you then allow for discrete form inputs for the three segments (day, month, year)?

Так или иначе, как Вы тогда разрешите отдельные поля ввода для трех частей (число, месяц, год)?

History of edits (Latest: victorgugo86 7 years, 1 month ago) §

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()? На самом деле здесь имеется ввиду вопрос о декораторе: как извлечь отдельные части элемента и/или установить их?

History of edits (Latest: victorgugo86 7 years, 1 month ago) §

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() Вашего элемента для применения собственной логики. В этом особенном случае наш элемент должен иметь три отдельных поведения:

History of edits (Latest: victorgugo86 7 years, 1 month ago) §

    • 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.

Pages: ← previous Ctrl next next untranslated
1 2 3 4 5 6