yii captcha

4805 단어 yiicaptcha
다음 코드를 설명의 보기 파일에 삽입합니다:views/comment/form.php

  
  
  
  
  1. <?php if (extension_loaded('gd')): ?> 
  2.         <div class="row"
  3.             <?php echo CHtml::activeLabelEx($model'verifyCode') ?> 
  4.         <div> 
  5.         <?php $this->widget('CCaptcha'); ?> 
  6.         <?php echo CHtml::activeTextField($model,'verifyCode'); ?> 
  7.         </div> 
  8.         <div class="hint">Please enter the letters as they are shown in the image above. 
  9.         <br/>Letters are not case-sensitive.</div> 
  10.         </div> 
  11.     <?php endif; ?> 

모델 Comment에서php에 다음 코드를 추가합니다.

  
  
  
  
  1. public $verifyCode

rules () 아래에 추가:

  
  
  
  
  1. array('verifyCode''captcha''allowEmpty'=>!Yii::app()->user->isGuest), 

attributeLabels()에서 다음을 추가합니다.

  
  
  
  
  1. 'verifyCode' => 'Verification Code'

컨트롤러 파일 controllers/PostController.php에서 다음 작업을 추가합니다.

  
  
  
  
  1. public function actions()    { 
  2.         return array
  3.             'captcha'=>array
  4.                 'class'=>'CCaptchaAction'
  5.                 'backColor'=>0xFFFFFF, 
  6.             ), 
  7.         ); 

이 때 rules에서'deny all'앞에 다음 코드를 추가합니다.

  
  
  
  
  1. array('allow'
  2.         'actions'=>array('captcha'), 
  3.         'users'=>array('*'), 
  4. ), 

다음으로 이동:http://www.yiichina.com/forum/thread-881-1-1.html

좋은 웹페이지 즐겨찾기