A
A
alex4answ2019-03-22 14:36:50
Yii
alex4answ, 2019-03-22 14:36:50

Convert to lowercase before saving?

Good afternoon, I can't figure out how to keep the text in lower case: I
apply a filter:

public function rules()
    {
          ...
          ['username', 'filter', 'filter' => 'strtolower'],
    }

But saves all the same as entered by the user.
Most likely, I do not understand correctly how it works, and that the filter in the validation rules will not do this, but should I translate everything into beforeSave ?
Can you please tell me if the filter in the rules is applied or not?
how to implement it correctly

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
morricone85, 2019-03-22
@morricone85

you can write like this:

['username', 'filter', 'filter' => function ($value) {
                return strtolower($value);
    }],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question