纠结的问题 最后只是选择了默认的配置
上代码:
model :
public function rules() { return [ ['username', 'filter', 'filter' => 'trim'], ['username', 'required'], ['username', 'unique', 'targetClass' => '\common\models\Adminuser', 'message' => '用户名已经存在.'], ['username', 'string', 'min' => 2, 'max' => 255], ['email', 'filter', 'filter' => 'trim'], ['email', 'required'], ['email', 'email'], ['email', 'string', 'max' => 255], ['email', 'unique', 'targetClass' => '\common\models\Adminuser', 'message' => '邮件地址已经存在.'], ['password', 'required'], ['password', 'string', 'min' => 6], ['password_repeat','compare','compareAttribute'=>'password','message'=>'两次输入的密码不一致!'], ['nickname','required'], ['nickname','string','max'=>128], ['profile','string'], ['verifyCode','captcha', 'captchaAction' => '/backend/Adminuser/captcha'], ]; }
控制器:
public function actions() { return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], 'captcha' => [ 'class' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, ], ]; }view:
= $form->field($model,'verifyCode')->widget(Captcha::ClassName(),[ 'captchaAction' => 'Adminuser/captcha', 'template' => '', ]) ?>{image}{input}
解决:
怎么调整都不行 之后跟踪到报错的位置: /vendor/yiisoft/yii2/captcha/CaptchaValidator.php:81
发现了这样的一行代码
$ca = Yii::$app->createController($this->captchaAction);
public $captchaAction = 'site/captcha';所以呢 怀疑是model里面的配置的问题 现在去掉了 model,view 里面的
'captchaAction' => '/backend/Adminuser/captcha'
控制器也去掉了 关于captcha的配置 然后不在报错
这时候验证码不显示 怀疑是权限的问题 ,添加了红色的部分 ok
public function behaviors() { return [ 'access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'actions' => ['login', 'error','captcha'], 'allow' => true, ], [ 'actions' => ['logout', 'index'], 'allow' => true, 'roles' => ['@'], ], ], ], 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'logout' => ['post'], ], ], ]; }