我有一個小問題在ZF2Zend框架2:看不見驗證碼
這裏生成的驗證碼是我的控制器:
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>
...
Abo ve代碼在data/captcha文件夾中生成png圖像,但我無法在視圖中生成它們。 FireBug顯示img元素和網址,但圖像網址似乎是空的。 感謝您的幫助。
你./data/captcha目錄是從瀏覽器的網址 – kta