将类添加到围绕

发布于 2024-08-31 15:01:11 字数 1396 浏览 2 评论 0原文

我正在尝试

<div class="group wat-cf">
  <div class="left">
    <label class="label right">Username</label>
  </div>
  <div class="right">
    <input type="text" class="text_field">
  </div>
</div>

使用以下代码从 Zend_Form 中获取以下 html:

$username->setAttrib("class", "text_field")
         ->setDecorators(array(
                           'ViewHelper',
                               'Description',
                   'Errors',
                   array(array('data'=>'HtmlTag'), array('tag' => 'div', 'class' => 'right')),
                               array('Label', array('tag' => 'div', 'class' => 'label right')),
                               array(array('row'=>'HtmlTag'),array('tag'=>'div', 'class' => 'group wat-cf'))
            ));

我可以获取下一个片段

<div class="group wat-cf">
  <div id="username-label">
    <label for="username" class="label right required">Username:</label>
  </div>
  <div class="right">
    <input type="text" name="username" id="username" value="" class="text_field">
  </div>
</div>

,因此除了一些额外的 id 和我不介意的所需类之外,我需要在 div id 上获取一个“left”类="username-label"

现在将类添加到标签行,获取添加到元素上的类。我也没有在标签装饰器代码本身中看到执行此操作的选项。所以我需要一个自定义标签装饰器,或者我缺少其他方法吗?

I'm trying to get the following html out of Zend_Form

<div class="group wat-cf">
  <div class="left">
    <label class="label right">Username</label>
  </div>
  <div class="right">
    <input type="text" class="text_field">
  </div>
</div>

Using the following code:

$username->setAttrib("class", "text_field")
         ->setDecorators(array(
                           'ViewHelper',
                               'Description',
                   'Errors',
                   array(array('data'=>'HtmlTag'), array('tag' => 'div', 'class' => 'right')),
                               array('Label', array('tag' => 'div', 'class' => 'label right')),
                               array(array('row'=>'HtmlTag'),array('tag'=>'div', 'class' => 'group wat-cf'))
            ));

I can get the next fragment

<div class="group wat-cf">
  <div id="username-label">
    <label for="username" class="label right required">Username:</label>
  </div>
  <div class="right">
    <input type="text" name="username" id="username" value="" class="text_field">
  </div>
</div>

so apart from some extra id's and required classes i don't mind, i need to get a class "left" on div id="username-label"

Now adding class to the Label line, gets the class added on the element. I also don't see and option to do this in the Label decorator code itself. So i need a custom Label decorator, or is there some other way i'm missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟沫凡尘 2024-09-07 15:01:11

在较新版本的 Zend 中,您可以添加 tagClass 参数。
请参阅下面的“标签”数组

$username->setAttrib("class", "text_field")
     ->setDecorators(array(
               'ViewHelper',
               'Description',
               'Errors',
               array(array('data'=>'HtmlTag'),array('tag' => 'div', 'class' => 'right')),
               array('Label', array('tag' => 'div', 'tagClass' => 'left', 'class' => 'label right')),
               array(array('row'=>'HtmlTag'),array('tag'=>'div', 'class' => 'group wat-cf'))
        ));

In newer versions of Zend you can add the tagClass parameter.
See below in the "Label" array

$username->setAttrib("class", "text_field")
     ->setDecorators(array(
               'ViewHelper',
               'Description',
               'Errors',
               array(array('data'=>'HtmlTag'),array('tag' => 'div', 'class' => 'right')),
               array('Label', array('tag' => 'div', 'tagClass' => 'left', 'class' => 'label right')),
               array(array('row'=>'HtmlTag'),array('tag'=>'div', 'class' => 'group wat-cf'))
        ));
瀞厅☆埖开 2024-09-07 15:01:11

这是一个很常见的问题。我认为,这个答案在这种情况下也可能有帮助:

添加一些html 到 Zend Forms

看一下 Padraic 的教程 以及。

This is pretty common question. I think, that this answer may by helpful in this case too:

Add some html to Zend Forms

Take look at Padraic's tutorial as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文