在HappyController 中加入
public function actions(){
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
‘captcha‘=>array(
‘class‘=>‘CCaptchaAction‘,
‘backColor‘=>0xFFFFFF, //背景颜色
‘minLength‘=>4, //最短为4位
‘maxLength‘=>4, //是长为4位
‘transparent‘=>true, //显示为透明
),
);
}
public function actionIndex(){
$this->layout = false;
$this->render(‘index‘);
}
在view视图中,添加如下代码,就可以得到验证码了。
<?php $this->widget(‘CCaptcha‘); ?>
原文:http://www.cnblogs.com/xiaoxiao2014/p/3924134.html