[ 'class' => 'common\helpers\CaptchaAction', 'width' => 120, 'height' => 40, 'padding' => 0, 'minLength' => 4, 'maxLength' => 4, 'offset'=>8, //设置字符偏移量 有效果 'testLimit'=>1, ], ]; } /** * 不允许直接访问ajax页面 * @param $action * @return bool * @throws \yii\web\BadRequestHttpException */ protected function checkAjax(&$action){ $currentAction = $action->id; if(strpos($currentAction ,'ajax-')===0){ if(!\Yii::$app->request->getIsAjax()){ throw new \yii\web\BadRequestHttpException('无法完成您的请求'); } } return true; } }