0
我在yii2一個模式類定義爲添加自定義消息,屬性確認在擴展模態在yii2
return [
[['charity_name', 'address', 'contact_name', 'title', 'dialling_code', 'phone_no', 'email', 'notes', 'added_by', 'created_at'], 'required'],
[['dialling_code', 'phone_no', 'added_by', 'created_at', 'status'], 'integer'],
[['charity_name', 'contact_name', 'email'], 'string', 'max' => 100],
[['address', 'title'], 'string', 'max' => 200],
[['notes'], 'string', 'max' => 255],
[['charity_name'], 'unique'],
[['added_by'], 'exist', 'skipOnError' => true, 'targetClass' => Users::className(), 'targetAttribute' => ['added_by' => 'id']],
[['dialling_code'], 'exist', 'skipOnError' => true, 'targetClass' => CountryDiallingCodes::className(), 'targetAttribute' => ['dialling_code' => 'id']],
];
我想表明的是「電話號碼應該是數字」的消息規則,所以我把下面擴展類的功能
public function rules() {
$rules = parent::rules();
$rules[] = [['phone_no'], 'integer', ['message'=>'Phone number should be numeric']];
return $rules;
}
但似乎並不奏效。請讓我知道我可以在擴展模態類添加自定義消息屬性
'$規則[] = [[ 'phone_no'], '整數', '消息'=> '電話號碼應該是數字'];' –
HI @AlwaysLearn:噸以下給出的答案ATLEAST答覆。無論它是否奏效。 –