当前位置: 代码迷 >> 综合 >> Yii,验证码内置验证码调用
  详细解决方案

Yii,验证码内置验证码调用

热度:67   发布时间:2024-01-18 11:40:51.0

在需要放置验证码页面的控制器中

 

一、 放入actions方法,载入验证码类

 

public function actions()
 {
  return array(
    // captcha action renders the CAPTCHA image displayed on the contact page
    'captcha'=>array(
      'class'=>'CCaptchaAction',
      'backColor'=>0xFFFFFF,
      'maxLength'=>'4',       // 最多生成几个字符
      'minLength'=>'3',       // 最少生成几个字符
      'height'=>'35'
    ),
  );
 }

二、配置访问限制规则

 public function accessRules()
 {
  return array(
    array('allow',  //允许所有人执行'login','error','index'
      'actions'=>array('index','captcha'),
      'users'=>array('*'),
     ),
    );
 }

 

三、view 层,相关页面写入验证码


                       

四、控制器层,验证方法中添加代码获取验证码

  $checkCode = $this->createAction('captcha')->getVerifyCode();

 


 

 

  相关解决方案