yii captcha没有显示在视图中

问题描述 投票:0回答:2

我试图在我的注册页面上显示验证码,但是由于某种原因,它不会显示。 我正在使用YiiSkeletonApp

在我看来

   echo $form->captchaRow($model,'verify',array('class' => 'input-block-level',
            'hint'=>'<i class="muted">Letters are not case-sensitive.</i>',
        ));

在我的模型/ user.php中,我有这个

public function rules() {
return array(
array('verify', 'captcha', 'allowEmpty' => !CCaptcha::checkRequirements(), 'on' => 'register, forgotPassword'),
);

和我的controllers / UserController.php

public function accessRules() {
        return array(
            // Actions: index, create, update, password, newPassword, forgotPassword, delete
            array('allow',
                'actions' => array('captcha', 'create', 'forgotPassword', 'newPassword'),
                'expression' => 'app()->user->isGuest()',
            ),
            array('allow',
                'actions' => array('password', 'update'),
                'users' => array('@'),
            ),
            array('allow',
                'actions' => array('index', 'create', 'register', 'delete'),
                'expression' => 'app()->user->isAdmin()',
            ),
            array('deny',
                'users' => array('*'),
            ),
        );
    }
yii
2个回答
1
投票

CCaptcha要求安装gd扩展 。 如果不存在,则不会显示验证码。


0
投票

在您的控制器中,在action中对其进行定义:

public function actions()
    {
        return array(
            // captcha action renders the CAPTCHA image displayed on the contact page
            'captcha'=>array(
                'class'=>'CCaptchaAction',
                'backColor'=>0xFFFFFF,
            ),

        );
    }

现在应该可以工作了。

© www.soinside.com 2019 - 2024. All rights reserved.