Question

Hi all I'm trying to render this html structure with Zend :

<div id="medias" class="item">
    <h2> Medias </h2>
    <a id="addmedia" href="#">
        <img alt="" src="images/bigbtn-add.png">
    </a>
</div>

Update 1 :

This is how I create the media_img element :

$media_img = new Zend_Form_Element_Image('media_img');
$media_img->setImage("/img/bigbtn-add.png");
$this->addElement($media_img);

Using this :

$this->setElementDecorators(array(
    'ViewHelper',
    'HtmlTag', array('HtmlTag', array('tag' => 'a', 'id' => 'addmedia','href' => '#'))
),
array('media_img')
);

I properly render this part of my code :

<a id="addmedia" href="#">
    <img alt="" src="images/bigbtn-add.png">
</a>

How can I prepend the h2 and then wrap these elements inside my div ?

Update 2 :

Thanks to @Mubo's help, I render this html :

<h2 class="hint">Medias</h2>
<a id="addmedia" href="#">
    <input id="media_img" type="image" src="/img/bigbtn-add.png" name="media_img">
</a>

Now I only need to wrap all of these lines in a div. The decorator looks like this now :

$this->setElementDecorators(array(
    'ViewHelper',
    'HtmlTag', array('HtmlTag', array('tag' => 'a', 'id' => 'addmedia','href' => '#')),
    array('Description', array('tag' => 'h2', 'placement' => 'prepend')),
),
array('media_img')
);

What's missing ?

Thanks for your help.

Update 3 : I still can't figure it out...

Was it helpful?

Solution 2

Wow, I finally found a solution. Here is my decorator :

   $media_img->setDecorators(array(
        'ViewHelper',
        'Errors',
        array('HtmlTag', array('tag' => 'a', 'id' => 'addmedia','href' => '#')),
        array('Description', array('tag' => 'h2', 'placement' => 'prepend')),
        array(
            array('fieldDiv' => 'HtmlTag'), 
            array(
                'tag' => 'div', 'class' => 'item', 'id' => 'medias'
            )
        )
    ));

OTHER TIPS

You can use setDescription and prepend it with decorator like this.

This is very tricky and not straightforward.

     $myElement = new Zend_Form_Element_Text('name');
      $myElement->setLabel('Label');       
      $myElement->setRequired(true);
      $myElement->setDescription('Medias');        
      $myElement->setDecorators(   array(  'DijitElement', 'Errors',
                array(array('data' => 'HtmlTag'), array('tag' => 'td')),
                array('Label', array('tag' => 'td')),
                array('Description', array('tag' => 'h2', 'placement' => 'prepend')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => 'form_row'))
            ));
$this->addElement($myElement);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top