RSM*_*RSM 1 php model-view-controller zend-framework zend-form
通过命令行,我设置了一个名为BookSlot的新表单:
zf create form BookSlot
Run Code Online (Sandbox Code Playgroud)
大多数人都知道,在Zend框架的应用程序目录中创建一个表单目录.
在表单的init方法中,我添加了一个名为time的文本元素,并为其指定了标签'time':
$time = new Zend_Form_Element_Text('time');
$this->addElement($time);
$time->setLabel('Time');
Run Code Online (Sandbox Code Playgroud)
我需要它有一个默认值,用户无法更改,所以我添加:
$time->setValue($value);
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我创建了一个函数来获取上面的书槽形式:
public function getBookSlotForm(){
return new Application_Form_BookSlot();
}
Run Code Online (Sandbox Code Playgroud)
我的索引控制器中也有一个书槽操作.
我将表单分配给变量并使其可以通过书槽操作中的视图:
$form = $this->getBookSlotForm();
$this->view->form = $form;
Run Code Online (Sandbox Code Playgroud)
在相同的书槽操作中,我有一个动态生成的id变量,但为此假设它为5:
$id = 5;
Run Code Online (Sandbox Code Playgroud)
如何获取上面的书槽形式$id的默认值$time?此外,我想这样做,以便用户无法更改此值.
对于用户无法使用readOnly属性更改值.在您的表单类中
$time->setAttrib('readonly', 'readonly');
Run Code Online (Sandbox Code Playgroud)
要在您的操作中将您的ID指定为时间字段的默认值
$form->time->setValue($id);
Run Code Online (Sandbox Code Playgroud)