[Yii Framework] Captcha的使用方法

假设使用的model名字为Comment
Model里面
Public function rules()
{
Return array(
......
Array('verifyCode', 'captcha', 'on'=>'insert', 'allowEmpty'=>!Yii::app()->user->isGuest || !extension_loaded('gd')),
);
}
View里面
<form action=”/test/xyz” method=”post”>
<input type=”text” name=”comment[verifyCode]”/>
</form>
Controller里面
Public function xyz()
{
$comment = new Comment;
$comment->validate('insert');//因为是insert的时候才会用到captcha,所以要加上参数'insert'
}

posted @ 2010-04-21 11:44  DavidHHuan  阅读(688)  评论(0编辑  收藏  举报