code meaning in zend

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    code meaning in zend

    Code:
      $other->setDecorators(array(
            'Description' ,
            'Label' ,
            array(
                array('divLabel' => 'HtmlTag') ,
                array('tag' => 'div' , 'class' => 'fieldItemLabel')
            ) ,
            array(
                array('divInput' => 'HtmlTag') ,
                array('tag' => 'div' ,
                      'class' => 'fieldItemValue',
                      'openOnly' => true,
                      'placement' => Zend_Form_Decorator_Abstract::APPEND)
            ),
            'ViewHelper',
            'Errors',
            array(
                array('divInputClose' => 'HtmlTag') ,
                array('tag' => 'div' ,
                      'closeOnly' => true,
                      'placement' => Zend_Form_Decorator_Abstract::APPEND)
            ),
            array(
                array('divField' => 'HtmlTag') ,
                array('tag' => 'div' , 'class' => 'field80Pct')
            ),
            array(
                array('divClear' => 'HtmlTag') ,
                array('tag' => 'div' ,
                      'class' => 'clear',
                      'placement' => Zend_Form_Decorator_Abstract::APPEND)
            ),
        ));
    after searching for many days i found this for the zend form decorators .
    i am new to zend . can anyone just explain me how this code will be executed and how do i tell tht the class is for labels or for values or for whole element ! and what does it mean 'ViewHelper' and 'Errors' . where are the code for these 2 elements.

    I dono if i can ask zend question here .since it was php ,asking here.If its not allowed please discard the question.
  • zorgi
    Recognized Expert Contributor
    • Mar 2008
    • 431

    #2
    This is some sort of Zend_Form Decorator and probably single most difficult par of ZF to understand. Others can agree or disagree with that statement but that is my opinion. I love working with ZF but I absolutely hate Decorators.

    Tutorial: Decorators with Zend_Form is the bets tutorial on the subject I know of. However I am not sure that approaching to ZF like this is good idea. I would recommend you first learn ZF basics and how to use Zend_Form with default Decorators. Tutorial: Getting Started with Zend Framework 1.10 is good place to start. Very basic example but very good to get you going.

    Comment

    • pradeepjain
      Contributor
      • Jul 2007
      • 563

      #3
      yeah i know.i have gone through both the tutorials!but the decorators i was not able to understand a bit .so tot to seek help !!

      Comment

      • pradeepjain
        Contributor
        • Jul 2007
        • 563

        #4
        i got a beautiful explained code on zend forum .i would like to share the code over here .

        Code:
        $yourElement->addDecorator('Label')
                ->addDecorator('HtmlTag', array('tag'=>'div', 'class'=>'fieldItemLabel'))
                ->addDecorator('HtmlTag', array('tag'=>'div', 'class'=>'fieldItemValue', 'openOnly'=>true, 'placement'=>'append'))
                ->addDecorator('ViewHelper')
                ->addDecorator('HtmlTag', array('tag'=>'div', 'closeOnly'=>true, 'placement'=>'append'))
                ->addDecorator('HtmlTag', array('tag'=>'div', 'class'=>'field50Pct'));
        with explanation


        HtmlTag is rendered around all previously rendered content, unless you supply 'placement' option, like in that third and fifth call of addDecorator() method.

        So, here's how that example from my previous post works:
        1. label is rendered first
        2. div tag with class "fieldItemLabel " wraps around everything that is previously rendered (in this case only label)
        3. then we must only append opened next div tag with "fieldItemValue " CSS class
        4. viewHelper decorator is rendered, which is the actual textfield element
        5. then we close opened div from step 3
        6. And finally, we wrap div with "field50Pct " CSS class around everything that is previously rendered.

        Comment

        Working...