如何自定义错误消息以在Yii中添加ID?

Currently I am using $form->error($user_model,'password') this function to show error message which gives me output as <div class="errorMessage">Please enter current password</div> but I want to add id in same div. What changes I have to do for that?

To customize error message you have to go to user model and change/add your message to function rules() array.

function rules() {
   return [
      ['password', 'required', 'message' => 'Your custom message'],
   ];
}

Check CRequiredValidator class for more information.


To apply some custom ID:

$form->error($error_model, 'password', ['id' => 'My-super-custom-id']);

just it will break your error messages output when using yii-js methods.