Php Zend Framework 2-添加表单类

Php Zend Framework 2-添加表单类,php,zend-form,zend-framework2,Php,Zend Form,Zend Framework2,我就是找不到答案。。。是否有方法将CSS类传递给我的打开表单标签 例如,我想创建一个类为“form-horizontal”的表单 文件说: // Render the opening tag echo $this->form()->openTag($form); // <form action="/contact/process" method="post"> 谢谢 Ron好的,诀窍是使用setAttribute两次 在Form.php中执行此操作: $this->

我就是找不到答案。。。是否有方法将
CSS类
传递给我的
打开表单标签

例如,我想创建一个类为“form-horizontal”的表单

文件说:

// Render the opening tag
echo $this->form()->openTag($form);
// <form action="/contact/process" method="post">
谢谢


Ron

好的,诀窍是使用
setAttribute
两次

在Form.php中执行此操作:

$this->setAttribute('method', 'post');
$this->setAttribute('class', 'form-horizontal');
参考链接是:

您也可以使用

$this->setAttributes(array(
    'action' => '/someurl',
    'method' => 'post',
    'class'  => 'form-horizontal'
));
它的工作原理是使用

$this->setAttribute('method', 'post');
$this->setAttribute('class', 'form-horizontal');

另一个提示是:ZF2中出现的每一个
属性
都应该始终引用HTML属性。所有其他内容都被称为
选项
$this->setAttribute('method', 'post');
$this->setAttribute('class', 'form-horizontal');