Zend_form渲染问题

发布于 2024-08-05 04:55:00 字数 371 浏览 3 评论 0原文

我需要一个 zend_form ,其中主要包含复选框。我需要将它们分组并显示每个组的标题。例如

标题1

Label1 Check1

Label2 Check2

Label3 Check3

标题2

Label4 Check4

Label5 Check5

Label6 Check6

首先我不知道如何显示标题(“标题”)!有没有一种方法可以将标签添加到表单而不是元素或任何其他解决方案来在 Zend Form 中添加这些标题?

其次我该如何呈现这种方式?我应该使用什么样的装饰器? 我对装饰器有些了解,但我不太了解?

有人有什么想法吗? 谢谢!

I need a zend_form which will contain mostly checkboxes. I need to group them and also display a title for each group. e.g.

Heading 1

Label1 Check1

Label2 Check2

Label3 Check3

Heading 2

Label4 Check4

Label5 Check5

Label6 Check6

First I don't know how to display the title ("headings")! Is there a way that you can add a label to a form bu not to an element or any other solution to add these titles in Zend Form?

Second how do I render this way? what kind of decorator should I use?
I red something about decorators but I did not understand much of it?

Anybody any Idea?
thanx!

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

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

发布评论

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

评论(2

烟雨凡馨 2024-08-12 04:55:00

您可能对手册的这一部分感兴趣,这似乎正是您想要获得的内容:23.4.3。显示组 (引用)

显示组是一种创建
元素的虚拟分组
显示目的。所有元素均保留
通过表单中的名称可以访问,但是
当迭代表单或
渲染,显示中的任何元素
组一起呈现。最
常见的用例是
对字段集中的元素进行分组。

这应该允许您将表单元素重新分组到字段集中,并且每个元素都可以有其图例 - 在您的情况下,这将是“标题 X”。

将复选框添加到表单后,您应该能够使用以下内容重新分组它们:

$form->addDisplayGroup(array('checkbox1', 'checkbox2', 'checkbox3'), 'firstgroup');
$form->addDisplayGroup(array('checkbox4', 'checkbox5', 'checkbox6'), 'fsecondgroup');

对于渲染部分,我想它将使用 Zend_Form_Decorator_Fieldset

在评论后编辑

要设置每个组的标题,您必须设置其“图例”,并将其作为选项传递。

例如,这是我从很久以前从事的一个旧项目中找到的一段代码:

$form->addDisplayGroup(array(
    'idCategory',
    'date',
    // ...
    'tags', 
    'nbComments'
), 
'postmeta', 
array(
    'order' => 2,
    'attribs' => array(
        'class' => 'group',
        'legend' => 'Meta-données'
    )
));

Meta-données”,据我所知,是“legend< /code>”用于包含这些元素的字段集。

You might be interested by this section of the manual, which seems to be exactly about what you want to obtain : 23.4.3. Display Groups (quoting) :

Display groups are a way to create
virtual groupings of elements for
display purposes. All elements remain
accessible by name in the form, but
when iterating over the form or
rendering, any elements in a display
group are rendered together. The most
common use case for this is for
grouping elements in fieldsets.

This should allow you to have your form elements re-grouped in fieldsets, and each one of those can have its legend -- in your case, that would be "heading X".

Once your checkboxes have been added to the form, you should be able to re-group them by using something like this :

$form->addDisplayGroup(array('checkbox1', 'checkbox2', 'checkbox3'), 'firstgroup');
$form->addDisplayGroup(array('checkbox4', 'checkbox5', 'checkbox6'), 'fsecondgroup');

For the rendering part, I suppose it'll use Zend_Form_Decorator_Fieldset

Edit after the comment

To set the title of each group, you have to set its "legend", passing that as an option.

For example, here is a piece of code I found from an old project I worked on quite some time ago :

$form->addDisplayGroup(array(
    'idCategory',
    'date',
    // ...
    'tags', 
    'nbComments'
), 
'postmeta', 
array(
    'order' => 2,
    'attribs' => array(
        'class' => 'group',
        'legend' => 'Meta-données'
    )
));

The "Meta-données", from what I recall, is the "legend" used for the fieldset containing those elements.

以可爱出名 2024-08-12 04:55:00

尝试将此类添加

class Zend_Form_Element_Note extends Zend_Form_Element_Xhtml
{
    public $helper = 'formNote';    
}

到 /Your/Own/Form/Element 目录,例如,

$form->addPrefixPath( 'LSS_Form_Element', 'LSS/Form/Element', 'element' );

您可以添加“注释”元素类型,该类型仅显示标题等静态文本。例如

$form->addElement( 'note', 'my_note', array( 'label' => 'Heading 1' ) );

try adding this class

class Zend_Form_Element_Note extends Zend_Form_Element_Xhtml
{
    public $helper = 'formNote';    
}

to /Your/Own/Form/Element directory eg

$form->addPrefixPath( 'LSS_Form_Element', 'LSS/Form/Element', 'element' );

You can then add 'note' element types which just display static text like your headings. eg

$form->addElement( 'note', 'my_note', array( 'label' => 'Heading 1' ) );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文