How to name a model rule in Yii2?

I just started learning Yii2

and I have a problem here. I want to set a new rule on a field name

that will change all first letters to uppercase, but I don't know how to set the rule name and I keep getting error messages.

Now my model looks like this: I added a regex that replaces the letters with uppercase, but I don't know how to write this empty string:

['name', 'required'],
        ['name', 'string', 'max' => 255,
            ' ' => '/(^|\s)[a-z]/g'],

      

Thanks for any help

+3


source to share


1 answer


For this simple case, just use

['name', 'filter', 'filter' => 'ucfirst']

      



See the docs for this.

+4


source







All Articles