控制器中:
$this->codeSession = new Zend_Session_Namespace('code'); //在默认构造函数里实例化
$captcha = new Zend_Captcha_Image(array('font'=>'public/images/verdanaz.ttf', //字体文件路径
'fontsize'=>12, //字号
'imgdir'=>'public/images/code/', //验证码图片存放位置
'session'=>$this->codeSession, //验证码session值
'width'=>60, //图片宽
'height'=>30, //图片高
'wordlen'=>4 )); //字母数
$captcha->setDotNoiseLevel(5); //设置验证码背景图片中的混淆点个数,默认为100
$captcha->setGcFreq(3); //设置删除生成的旧的验证码图片的随机机率
$captcha->generate(); //生成图片
$this->view->ImgDir = $captcha->getImgDir();
$this->view->captchaId = $captcha->getId(); //获取文件名,md5编码
$this->codeSession->code=$captcha->getWord(); //获取当前生成的验证字符串
echo $this->codeSession->code;//得到的是验证码中的数字
$this->codeSession = new Zend_Session_Namespace('code'); //在默认构造函数里实例化
$captcha = new Zend_Captcha_Image(array('font'=>'public/images/verdanaz.ttf', //字体文件路径
'fontsize'=>12, //字号
'imgdir'=>'public/images/code/', //验证码图片存放位置
'session'=>$this->codeSession, //验证码session值
'width'=>60, //图片宽
'height'=>30, //图片高
'wordlen'=>4 )); //字母数
$captcha->setDotNoiseLevel(5); //设置验证码背景图片中的混淆点个数,默认为100
$captcha->setGcFreq(3); //设置删除生成的旧的验证码图片的随机机率
$captcha->generate(); //生成图片
$this->view->ImgDir = $captcha->getImgDir();
$this->view->captchaId = $captcha->getId(); //获取文件名,md5编码
$this->codeSession->code=$captcha->getWord(); //获取当前生成的验证字符串
echo $this->codeSession->code;//得到的是验证码中的数字
视图中:在需要引用验证码的地方加上
<img src="<?php echo $this->ImgDir .'/'.$this->captchaId "></img