我目前有一個表單,可以讓你創建一個家庭。PHP Zend表單設置值
FamilyForm.php
$description = new Textarea(self::KEY_FAMILY_DESCRIPTION);
$description->setAttribute("id", self::KEY_FAMILY_DESCRIPTION);
$description->setLabel("Description");
$this->add($description);
$status = new Hidden(self::KEY_FAMILY_STATUS);
$status->setAttribute("id", self::KEY_FAMILY_STATUS);
$this->add($status);
$save = new Button(self::KEY_SAVE_BTN);
$save->setAttributes(array("id", self::KEY_SAVE_BTN));
$save->setLabel("Save");
$save->setValue("Save");
$this->add($save);
Create.phtml
<?php echo ctrlGroup($this, ProjectFamilyForm::KEY_FAMILY_DESCRIPTION, !($this->admin)); ?>
<?php echo ctrlGroup($this, ProjectFamilyForm::KEY_FAMILY_STATUS, !($this->admin)); ?>
<div class="form-actions">
<?php $save = $this->form->get(ProjectFamilyForm::KEY_SAVE_BTN); ?>
<?php $save->setAttribute("class", "btn btn-primary"); ?>
<?php echo $this->formSubmit($save); ?>
<a class="btn" href="<?php echo $this->url('home'); ?>">Cancel</a>
</div>
這工作,並讓我輸入的說明並創建家庭中的地位。但是,每次創建家庭status
應該是"active"
。但是,setValue()
方法似乎不起作用。
* 「但我得到一個錯誤」 * - 作爲什麼*究竟* –
@ A-2-A是啊,錯過了我的副本? paste -_- –
@ Fred-ii-'調用一個非對象' –