相关疑难解决方法(0)

Yii2:条件验证器始终返回所需

我正在尝试使用指南中给出的Yii2的条件验证器,如:

型号代码

public function rules()
{
   // $discharged = function($model) { return $this->discharged == 1; };
    return [
        [[ 'admission_date','discharge_date', 'doctor_appointment_date', 'operation_date'], 'safe'],
        [[ 'package','tpa_name', 'discharged', 'bed_type', 'room_category', 'ref_doctor', 'consultant_doctor', 'operation_name'], 'integer'],
        [['advance_amount', 'operation_charges'], 'number'],
        [['patient_name', 'ref_doctor_other'], 'string', 'max' => 50],
        [['general_regn_no', 'ipd_patient_id'], 'string', 'max' => 20],
        [['admission_date', 'discharge_date', 'doctor_appointment_date', 'operation_date'],'default','value'=>null],
        ['ipd_patient_id', 'unique'],

        [['bed_type','admission_date','room_category'],'required'],

        ['discharge_date', 'required', 'when' => function($model) {
            return $model->discharged == 1;
        }],


    ];
}
Run Code Online (Sandbox Code Playgroud)

在我的控制器中像:

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

        if ($model->load(Yii::$app->request->post()) && $model->save()) …
Run Code Online (Sandbox Code Playgroud)

php validation yii2

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

php ×1

validation ×1

yii2 ×1