• Yii2 Lesson


    在SiteController.php中設置方法

        public function actionThree()
        {   
            $model = new Three();
            if($model->load(Yii::$app->request->post()) && $model->validate()) {
                Yii::$app->session->setFlash('success','Do it easy,Lesson 3');
            }   
            return $this->render('three',['model'=>$model]); 
        } 
    
    

    新建一個模型類 Three.php

    <?php
    namespace appmodels;
    use yiiaseModel;
    
    class Three extends Model{
        public $name;
        public $email;
    
      public function rules()
      {
        return [
                  [['name','email'],'required'],
                  ['email','email'],
               ];
      }
    }
    
    

    定一个视图文件 views/site/three.php

    <?php
    use yiihelpersHtml;
    use yiiwidgetsActiveForm;
    ?>
    <?php
            if(Yii::$app->session->hasFlash('success')){
                echo Yii::$app->session->getFlash('success');
            }
    
    ?>
    <?php  $form = ActiveForm::begin();?>
    <?= $form->field($model,'name');?>
    <?= $form->field($model,'email');?>
    <?= Html::submitButton('submit',['class'=>'btn btn-success']);?>
    ~                                                                   
    
    

    注意 commit 没反应的情况和 model中的rule格式有关系浪费我半小时

  • 相关阅读:
    memcached事故
    总算会用sphinx生成文档了
    python tip
    抓包工具wireshark
    狗日的用户体验
    python tip
    pymmseg
    memcached事故
    windwos序列号
    7z fromat on ubuntu&replace my fujishu electric fan
  • 原文地址:https://www.cnblogs.com/JsonM/p/7211738.html
Copyright © 2020-2023  润新知