1. Web ページを更新しても更新できないエラーの解決策:
ソースコードを変更しますvendor/yiisoft/yii2/captcha/CaptchaValidator.php
<code><span>/** *<span> @inheritdoc</span> */</span><span>public</span><span><span>function</span><span>clientValidateAttribute</span><span>(<span>$object</span>, <span>$attribute</span>, <span>$view</span>)</span> {</span><span>$captcha</span> = <span>$this</span>->createCaptchaAction(); <span>$code</span> = <span>$captcha</span>->getVerifyCode(<span>true</span>); <span>$hash</span> = <span>$captcha</span>->generateValidationHash(<span>$this</span>->caseSensitive ? <span>$code</span> : strtolower(<span>$code</span>)); <span>$options</span> = [ <span>'hash'</span> => <span>$hash</span>, <span>'hashKey'</span> => <span>'yiiCaptcha/'</span> . <span>$captcha</span>->getUniqueId(), <span>'caseSensitive'</span> => <span>$this</span>->caseSensitive, <span>'message'</span> => Yii::<span>$app</span>->getI18n()->format(<span>$this</span>->message, [ <span>'attribute'</span> => <span>$object</span>->getAttributeLabel(<span>$attribute</span>), ], Yii::<span>$app</span>->language), ]; <span>if</span> (<span>$this</span>->skipOnEmpty) { <span>$options</span>[<span>'skipOnEmpty'</span>] = <span>1</span>; } ValidationAsset::register(<span>$view</span>); <span>return</span><span>'yii.validation.captcha(value, messages, '</span> . json_encode(<span>$options</span>, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . <span>');'</span>; } }</code>
<code><span>$code</span><span>=</span><span>$captcha</span><span>-></span>getVerifyCode(<span>false</span>); <span>false</span>改成<span>true</span></code>
別の外観
解決策:
モデルの captchaAction の値を変更します
<code> [<span>'verifyCode'</span>, <span>'captcha'</span>,<span>'message'</span> =><span>'验证码错误'</span>,<span>'captchaAction'</span>=><span>'login/captcha'</span>],</code>
ビュー内:
<code><span><span><?</span>= <span>$form</span>->field(<span>$loginForm</span>, <span>'verifyCode'</span>,[<span>'options'</span>=>[<span>'class'</span> => <span>'form-group'</span>]])->widget(Captcha::className(),[ <span>'captchaAction'</span> => <span>'/login/captcha'</span>, <span>'imageOptions'</span> => [<span>'alt'</span>=><span>'点击换图'</span>,<span>'title'</span>=><span>'点击换图'</span>,<span>'style'</span>=><span>'cursor:pointer'</span>], <span>'options'</span> => [ <span>'placeholder'</span> => <span>'验证码'</span>, <span>'class'</span> => <span>'form-control'</span>, <span>'style'</span> => <span>'margin-top:10px;'</span> ] ])->label(<span>false</span>); <span>?></span></span></span></code>
上記では、Web ページ/サイト/キャプチャエラーが発生すると yii20 検証コードが更新できないことを紹介しました。関連する内容も含めて、PHP チュートリアルに興味のある友人に役立つことを願っています。