search

Home  >  Q&A  >  body text

php - yii rules how to add validation for a non-database field?

For example, I want to add a verification for field A, but it does not exist in the database. An error will be reported at this time. Are there any parameters that can be set?

黄舟黄舟2796 days ago658

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-05-17 09:57:59

    Override rulesMethod

    class Model extends \yii\db\ActiveRecord
    {
        //...
        public function rules() {
            $rules = parent::rules();
            $rules[] = [['phone'],'integer','message'=>'手机号码必须是数字'];
            return $rules;
        }
        //...
    }

    reply
    0
  • Cancelreply