Php Zend验证码问题

Php Zend验证码问题,php,zend-framework2,captcha,Php,Zend Framework2,Captcha,我是一个初学者,我遵循zend framework网站上的教程,从一个框架创建了一个简单的web应用程序。我试图向教程建议的表单中添加更多元素,尤其是“图像”capctha,但是,当我尝试在适当的视图中渲染它时,我遇到了以下致命错误: 致命错误:调用第45行C:\xampp\htdocs\new\vendor\zendframework\zendframework\library\Zend\Form\View\Helper\FormCaptcha.php中未定义的方法Zend\Form\Elem

我是一个初学者,我遵循zend framework网站上的教程,从一个框架创建了一个简单的web应用程序。我试图向教程建议的表单中添加更多元素,尤其是“图像”capctha,但是,当我尝试在适当的视图中渲染它时,我遇到了以下致命错误:

致命错误:调用第45行C:\xampp\htdocs\new\vendor\zendframework\zendframework\library\Zend\Form\View\Helper\FormCaptcha.php中未定义的方法Zend\Form\Element::getCaptcha()

这是与albumform类相关的代码:

 <?php

    namespace Album\Form;



     use Zend\Form\Element;
     use Zend\Form\Form;
     use Zend\Captcha\Image;
     use Zend\Captcha\AdapterInterface;

     class AlbumForm extends Form
     {
         protected $captcha; 
         public function __construct($name = null)
         {
             // we want to ignore the name passed
             parent::__construct('album');

             $this->captcha = new Image(array(
                'expiration' => '300',
                'wordlen' => '7',
                'font' => 'public/fonts/glyphicons-halflings-regular.tff',
                'fontSize' => '20',
                'imgDir' => 'public/captcha',
                'imgUrl' => '/captcha'
            ));

             $this->add(array(
                 'name' => 'id',
                 'type' => 'Hidden',
             ));
             $this->add(array(
                 'name' => 'title',
                 'type' => 'Text',
                 'options' => array(
                     'label' => 'Title',
                 ),
                 'attributes' => array(
                     'value' => 'Scrivi il titolo',
                     'class' => 'prova',
                 ),
             ));
             $this->add(array(
                 'name' => 'artist',
                 'type' => 'Text',
                 'options' => array(
                     'label' => 'Artist',
                 ),
             ));

              $this->add(array(
                'name' => 'captcha',
                'attributes' => array(
                   'type' => 'Captcha'
                ),
                'options' => array(
                   'label' => 'Please verify you are human.',
                   'captcha' => $this->captcha
                )
             ));

             $this->add(array(
                 'name' => 'submit',
                 'type' => 'Submit',
                 'attributes' => array(
                     'value' => 'Go',
                     'id' => 'submitbutton',
                 ),
             ));

         }
     }







你能帮帮我吗?少了什么


谢谢

问题出在元素定义中。你有:

$this->add(array(
    'name' => 'captcha',
    'attributes' => array(
        'type' => 'Captcha'
    ),
    'options' => array(
        'label' => 'Please verify you are human.',
        'captcha' => $this->captcha
    )
));
但是“类型”放错了地方。应该是:

$this->add(array(
    'name' => 'captcha',
    'type' => 'Captcha'
    'options' => array(
        'label' => 'Please verify you are human.',
        'captcha' => $this->captcha
    )
));

你是对的,同时我意识到我写了glyphicons-halflings-regular.tff而不是glyphicons-halflings-regular.ttf。现在它完美地工作了;谢谢!
$this->add(array(
    'name' => 'captcha',
    'type' => 'Captcha'
    'options' => array(
        'label' => 'Please verify you are human.',
        'captcha' => $this->captcha
    )
));