如何在表单中加载部分?

时间:2013-11-12 15:21:46

标签: zend-framework2

我目前正在将工具箱从Zend 1迁移到Zend2。我是这两种技术的新手。

在一种形式中,前一个工具箱通过装饰器加载和处理模板。

示例:

$this->setDecorators(array(array('ViewScript', array('viewScript' => 'forms/exemple-external.phtml'))));

我的模板:

<div class="row-fluid">
<div class="span10">
    <div class="row-fluid">
        <div class="span4">
            <div class="control-group">
                <label class="control-label" for="lastname">
                <button id="find-user" class="btn btn-mini" style="margin-right: 20px" type="button"><b>. . .</b></button>
                    Nom
                </label>
                <div class="controls">
                    <input type="text" id="lastname" name="lastname" placeholder="Nom" class="input-medium" value="<?php echo $this->lastname; ?>">
                </div>
            </div>
        </div><!--/span-->
        <div class="span4">
            <div class="control-group">
                <label class="control-label" for="firstname">Prénom</label>
                <div class="controls">
                    <input type="text" id="firstname" name="firstname" placeholder="Prénom" class="input-medium" value="<?php echo $this->firstname; ?>">
                </div>
            </div>
        </div><!--/span-->
        <div class="span4">
            <div class="control-group">
                <label class="control-label" for="active_directory_username">Nom LDAP</label>
                <div class="controls">
                    <input type="text" id="active_directory_username" name="active_directory_username" placeholder="Nom LDAP" class="input-medium" value="<?php echo $this->active_directory_username; ?>">
                </div>
            </div>
        </div><!--/span-->
    </div><!--/row-->
</div>   

如何在Zend2中模仿这种行为?此表单用作另一种形式的子表单。因此,这里的主要目标是能够在呈现父表单时呈现此模板。

你对这方面有任何线索吗?

1 个答案:

答案 0 :(得分:1)

您可以选择在集合上设置部分。我将与您分享我的代码,我认为这会增加您的时间。 在您看来:

$this->formCollection()->setElementHelper($this->formRow()->setPartial('partial/link-collection'));                   
echo $this->formCollection($addMovieForm->get('links'));

和部分/链接集合:

<?php if ($this->element instanceof \Zend\Form\Element\Button) : ?>
    <div class="control-group">
        <div class="controls">
            <?php echo $this->formElement($this->element) ?>
        </div>
    </div>
<?php else : ?>
    <div class="control-group">
        <?php echo $this->formLabel($this->element) ?>
        <div class="controls">
            <?php echo $this->formElement($this->element) ?>
            <?php echo $this->formElementErrors($this->element) ?>
        </div>

    </div>
<?php endif; ?>