jiji

 

  1. 修改models下的companies.php

 

/**
*
 @inheritdoc
*/public function rules()
{
    return [
        [[\'company_name\' , \'company_email\', \'company_address\', \'company_start_date\' , \'company_created_date\', \'company_status\'], \'required\'],
        [[\'company_start_date\' , \'company_created_date\'], \'safe\'],
        [[\'company_start_date\' ],\'checkDate\'],
        [[\'company_status\' ], \'string\'],
        [[\'company_name\' , \'company_email\', \'company_address\'], \'string\', \'max\' => 255]
    ];
}

 

 

public function checkDate ($attribute, $params){
   
 $today =date(\'Y-m-d\' );
   
 $selectedDate =date($this ->company_start_date);
   
 if ($selectedDate> $today){
       
 $this ->addError( $attribute,\'company start Date must be smaller !\');
    }
}

 

     2.修改_form.php文件

# code ...

<?php $form = ActiveForm:: begin([\'enableAjaxValidation\' =>true]); ?>

# code ...

 

     3.修改控制器文件

/**
* Creates a new Companies model.
* If creation is successful, the browser will be redirected to the \'view\' page.
*
 @return mixed
*/

public function actionCreate()
{
   
 $model = new Companies ();

   
 if (Yii:: $app->request ->isAjax && $model->load ($_POST)){
       
 Yii ::$app-> response->format =\'json\';
       
 return ActiveForm ::validate( $model);
    }

 


    if ($model-> load(Yii ::$app-> request->post ()) && $model->save ()) {
       
 return $this ->redirect([ \'view\', \'id\' => $model->company_id ]);
    }
 else {
       
 return $this ->render( \'create\', [
           
 \'model\' => $model,
        ]);
    }
}

来自于datou:https://github.com/datou-leo/ci

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2023-02-22
  • 2021-07-07
  • 2022-02-01
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-12
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案