要创建一个文本输入框,我在zend framework2中使用了folling代码
use Zend\Form\Form;
class Loginform extends Form
{
public function __construct()
{
$this->add(array(
'name' => 'usernames',
'attributes' => array(
'id' => 'usernames',
'type' => 'text',
),
'options' => array(
'label' => 'User Name',
),
));
}
}
Run Code Online (Sandbox Code Playgroud)
我可以使用控件操作填充值
$form = new Loginform();
$form->get('usernames')->setAttribute('value', 'user 1');
Run Code Online (Sandbox Code Playgroud)
知道如何在zf2中的选择/下拉框中执行相同的操作?
参考:zend框架2文档
我正在学习zf2,我正面临一个涉及2个(最终更多)模块一起工作的问题.请注意,我仔细阅读了这篇文章(以及相关文章),这对我帮助很大.我将解释一下这个问题:
id | field_name | field_value
1 | country | germany |
2 |国内|法国|
3 |性别|男|
4 |性别|女|
5 | TIPO |汽车|
6 | TIPO |飞|
...
ID |名称| id_tipo |
1 |菲亚特| 5 |
2 |莎| 6 |
3 |福特| 5 |
4 |法国航空6 |
...
(id_tipo是一个选项FK)
还要考虑:
作为测试,我在表单类中添加了这个字段,在视图和编辑模式下一切正常:
$this->add(
'type' => 'Zend\Form\Element\Select',
'name' => 'id_tipo',
'options' => array (
'label' => 'Tipo',
'empty_option' => 'Select',
'value_options' => array ('5' …Run Code Online (Sandbox Code Playgroud)