0

ZF2でキャプチャを生成するのに少し問題があります

これが私のコントローラーです:

public function indexAction()
{
    $form = new RegisterForm();

    return array('form' => $form);
}

RegisterForm クラス:

    public function __construct($name = null)
    {
        $this->url = $name;
        parent::__construct('register');
        $this->setAttributes(array(
            'method' => 'post'
        ));

        $this->add(array(
            'name' => 'password',
            'attributes' => array(
                'type'  => 'password',
                'id' => 'password'
            )
        ));
        $this->get('password')->setLabel('Password: ');

        $captcha = new Captcha\Image();
        $captcha->setFont('./data/captcha/font/arial.ttf');
        $captcha->setImgDir('./data/captcha');
        $captcha->setImgUrl('./data/captcha');



        $this->add(array(
            'type' => 'Zend\Form\Element\Captcha',
            'name' => 'captcha',
            'options' => array(
                'label' => 'Captcha',
                'captcha' => $captcha,
            ),
        ));

        $this->add(array(
            'name' => 'submit',
            'attributes' => array(
                'type'  => 'button',
                'value' => 'Register',
            ),
        ));
}

ビュー: index.phtml:

...
<div class="group">
    <?php echo $this->formlabel($form->get('captcha')); ?>
    <div class="control-group">
        <?php echo $this->formElementErrors($form->get('captcha')) ?>
        <?php echo $this->formCaptcha($form->get('captcha')); ?>
    </div>
</div>
...

上記のコードは、data/captcha フォルダーに png 画像を生成しますが、それらをビューで生成できません。FireBug には img 要素と URL が表示されますが、画像への URL は空のようです。助けてくれてありがとう。

4

1 に答える 1