开发者

Zend Framework - which decorators to use?

I want to change the html markup. I want to change the <dl> for a <div> tag a开发者_Python百科nd wrap the label and element together in a <div> tag so that I can apply floats to them. At the moment my element output looks like this:

<fieldset id="fieldset-languages">
    <legend>Languages</legend>
    <dl>

        <dt id="lang1-label">
            <label for="lang1" class="optional">Language</label>
        </dt>
        <dd id="lang1-element">
            <select name="lang1" id="lang1" class="input-select">
                <option value="0" label="English">English</option>
                <option value="1" label="French">French</option>
            </select>
        </dd>

        <dt id="lang2-label">
            <label for="lang1" class="optional">Language</label>
        </dt>
        <dd id="lang2-element">
            <select name="lang2" id="lang2" class="input-select">
                <option value="0" label="German">German</option>
                <option value="1" label="Spanish">Spanish</option>
            </select>
        </dd>

    </dl>
</fieldset>

and I want to change it to this...

<fieldset id="fieldset-languages">
    <legend>Languages</legend>
    <div>
        <div>
            <p id="lang1-label">
                <label for="lang1" class="optional">Language</label>
            </p>
            <p id="lang1-element">
                <select name="lang1" id="lang1" class="input-select">
                    <option value="0" label="English">English</option>
                    <option value="1" label="French">French</option>
                </select>
            </p>
        </div>

        <div>
            <p id="lang2-label">
                <label for="lang1" class="optional">Language</label>
            </p>
            <p id="lang2-element">
                <select name="lang2" id="lang2" class="input-select">
                    <option value="0" label="German">German</option>
                    <option value="1" label="Spanish">Spanish</option>
                </select>
            </p>
        </div>

    </div>
</fieldset>

I've already figured out I can change the dt/dd to <p> tags using the Html decorator - but can't wrap the label and element in a div.


your decorators should look like this (just an example):

      $this->setDecorators(array(
         'ViewHelper',
          array('Description', array('tag' => 'p', 'class' => 'description')),
          'Errors',
          array('HtmlTag', array('tag' => 'div')),
          array('Label', array('tag' => 'p')),
          array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div')),
      ));

you can read the "Customizing Output Using Standard Decorators" section of this article at least, it was helpful for me to understand how the form decorators works

quoted from the article:

"When adding a decorator, you have the option to alias it. What this does is allow you to store the decorator using a different name -- which allows you to retrieve it from the stack by that name. This is primarily useful when you need to add two or more of the same type of decorator; in fact, in such a situation, if you do not alias, the last registered decorator of that type will overwrite all other instances! You accomplish aliasing by passing an array as the decorator type, with a single key/value pair with the alias as the key, and the decorator type as the value. For instance, if you needed to use two different HTML tags in your stack, you could do something like the following ..."

(keep on reading this part of the section ;-))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜