Saturday, 14 April 2012

Yii Framework how to use Captcha

For Yii Framework Captcha:


Step 0: Make sure the gd2 ext. is enabled:
e.g., extension=php_gd2.dll


Step 1: Add the Captcha widget to your targeted view:
e.g.,  $this->widget("CCaptcha", array('buttonLabel'=>'change one for me', 'buttonOptions'=>array('style'=>'margin-bottom:20px;')));

Step 2: Config the Captcha in the controller class: (override its parent actions function):
e.g., public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
);
}

Step 3: Add a field such as VerifyCode to your Form model class in order to store the client's entered Captcha value:
e.g., class LoginForm extends CFormModel
{
public $verifyCode;
}

Step 4: Add the Captcha checking rule to your model class:

e.g., public function rules()
{
return array(
array('verifyCode', 'captcha', 'allowEmpty'=> !extension_loaded('gd')),
);
}




帮自己宣传一下刚上线的网站 梦奇网;目前的提供的服务是 签证搜索 和 时间和日期。谢谢大家支持,SEO下!

2 comments:

  1. Great Tutorial....its working....Thnxxxxxxxxxxxxxx

    ReplyDelete
  2. awesome topic it is very useful for me.
    visit us

    ReplyDelete