我正在使用Slim3和Zend Forms 2.6(https://packagist.org/packages/zendframework/zend-form)。我正在尝试渲染表单,但是我收到错误:
Fatal error: Call to undefined method QuizApp\Forms\QuizForm::render() in /var/www/QuizApp/Routes/SurveyRoutes.php on line 25
我已将我的表单添加为Slim3中的服务:
$container['QuizForm'] = function() use ($app) {
return new \QuizApp\Forms\QuizForm($app->SurveyServices);
};
这是我的表格:
class QuizForm extends \Zend\Form\Form
{
private $survey_services;
public function __construct(SurveyServices $survey_services, $name = null)
{
$this->survey_services = $survey_services;
parent::__construct($name);
}
public function init()
{
/*
* Set form method to POST
*/
$this->setMethod('POST');
/*
* Add submit button to the form
*/
$this->add(array(
'name' => 'submit',
'type' => 'Submit',
'attributes' => array(
'value' => 'Get Quiz Results'
),
));
}
}
我正试图在我的一条路线中渲染表格(最终我会将此传递给我,但我正在测试):
$form = $this->QuizForm;
# Doesn't work
print $form;
# Doesn't work
print $form->render()
令我困惑的是文档说打印表单应该有效:http://framework.zend.com/manual/1.12/en/zend.form.quickstart.html#zend.form.quickstart.render
我没有使用Zend Framework。我只使用表单组件。
如何呈现表单?