1、在控制器添加一下代碼
public?function?actionCaptcha(){ ????$c?=?YII::createObject('yiicaptchaCaptchaAction',?['__captcha',?$this]); ????$c->getVerifyCode(true); ????return?$c->run(); }
2、通過以下方法調用驗證碼
$c?=?Yii::createObject('yiicaptchaCaptchaAction',?['__captcha',?$this]); $code?=?$c->getVerifyCode();
$code就是之前生成的驗證碼
注意:$this代表當前控制器,此方法只適合在一個控制器使用。
3、前端調用:
寫個
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END