最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Yii2下點(diǎn)擊驗(yàn)證碼的切換實(shí)例代碼

 更新時(shí)間:2017年03月14日 10:46:15   作者:索海放由  
本篇文章主要介紹了Yii2下驗(yàn)證碼的切換實(shí)例代碼,實(shí)例分析了Yii2下驗(yàn)證碼的切換的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下。

最近需要用到驗(yàn)證碼,搜索了很多關(guān)于Yii2驗(yàn)證碼的切換的介紹,下面我來記錄一下,有需要了解Yii2下驗(yàn)證碼的切換的朋友可參考。希望此文章對(duì)各位有所幫助。

模型代碼如下:

<?php
namespace app\admin\models;
use yii;
use yii\base\model;
use yii\captcha\Captcha;
class LoginForm extends Model{
  public $verifyCode;
  public $password;
  public $username;
  public function rules(){
    return [
      ['verifyCode','captcha','captchaAction'=>'/admin/login/captcha','message'=>'{attribute}'],
      [['password','username'],'required'],
    ];

  }
}

控制器代碼如下:

<?php
namespace app\admin\controllers;
use Yii;
use yii\web\Controller;
use app\admin\models\LoginForm;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\captcha\CaptchaAction;
class LoginController extends Controller{

 public function actions(){
   return [
     'captcha'=>'yii\captcha\CaptchaAction',
     'maxLength'=>4,
     'minLength'=>3,
     'width'=>10,
     'height'=>10
   ];
  }

  public function actionIndex(){
    $log = new LoginForm();
    
     return $this->renderPartial("index",['model'=>$log]);
  }
  //授權(quán)規(guī)則
}

視圖代碼如下:

<?php
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use app\assets\AppAsset;
use yii\widgets\ActiveFiel;
use yii\widgets\ActiveForm;
use yii\captcha\Captcha;
use app\components\HelloWidget;
//url 創(chuàng)建
use yii\helpers\Url;
AppAsset::register($this);
?>
<?php $this->beginPage()?>
<!DOCTYPE html>
<html>
<head>
  <title>博客后臺(tái)管理系統(tǒng)</title>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <?=Html::cssFile('@web/css/bootstrap.min.css')?>
  <?=Html::cssFile('@web/css/style.css')?>
  <?=Html::jsFile("@web/js/jquery-1.11.3.min.js");?>
  <?=Html::jsFile("@web/js/bootstrap.min.js");?>
<?php ?>

</head>
  <?php $this->beginBody()?>
<body>
<div class="login-box">
  <div class="login">
    <div class="login-icon">

    </div>
    <h4 class="login-title">博客后臺(tái)管理系統(tǒng)</h4>
    <?php $form=ActiveForm::begin(['method'=>'post','action'=> \Yii::$app->urlManager->createUrl('/admin/login/index')])?>
      <div class="login-input-box mb10">
       <input type="text" class="form-control" name="username" placeholder="用戶名">
      </div>
      <div class="login-input-box mb10">

        <input class="form-control" type="password" name="password" placeholder="密碼">
      </div>
      <div class="login-input-box mb30">
        <input class="form-control" type="text" name="code" placeholder="驗(yàn)證碼">

        <span class="login-code">
          <img id="code_img" src="<?= Url::toRoute('/admin/login/captcha')?>" title="點(diǎn)擊刷新驗(yàn)證碼" onClick="get_code(this);">
        </span>
      </div>
      <input class="inputbtn bg-success btn-block" type="submit" value="登 錄">
    <?php ActiveForm::end();?>
  </div>
</div>
<script type="text/javascript">
  //刷新驗(yàn)證碼
  function get_code(obj)
  {

    if(!obj)
    {
      obj = document.getElementById('code_img');
    }
    obj.src = obj.src + "&t="+Date.parse(new Date());
  }
</script>
</body>
  <?php $this->beginBody()?>
</html>

<?php $this->endPage()?>

這里整個(gè)代碼差不多了但是要設(shè)置一樣更重要的 app/vendor/yiisoft/yii2/captcha/的文件下的CaptchaAction.php這文件中修改getVerifyCode($regenerate = false) 的方法$regenerate參數(shù)為true (getVerifyCode($regenerate = true))

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

武安市| 金溪县| 秭归县| 蓬莱市| 泸定县| 永德县| 巫溪县| 五常市| 富川| 蒲城县| 宁乡县| 视频| 黔江区| 抚松县| 靖边县| 胶州市| 呼伦贝尔市| 句容市| 松江区| 洪江市| 宜兰县| 睢宁县| 霍城县| 乌兰县| 河西区| 苏州市| 高碑店市| 肇庆市| 竹山县| 凯里市| 扶沟县| 佛冈县| 嫩江县| 宜兴市| 白河县| 桂阳县| 赤城县| 北碚区| 招远市| 漾濞| 周口市|