I am using Yii2 and attempting to implement a rule on my usernames so that they are always stored and compared in lowercase. If there a rule that I can use to make this possible?
For instance, I have a function that checks if username exists in the database. I want to avoid logic errors and implement a global rule if possible. Thanks for any tips!
Yii2 Rules:
/**
* @inheritdoc
*/
public function rules()
{
return [
[['username', 'password'], 'required'],
[['access_level'], 'integer'],
[['username'], 'string', 'max' => 50], // force lowercase?
[['username_print'], 'string', 'max' => 50],
[['password'], 'string', 'max' => 512],
[['email'], 'string', 'max' => 250],
[['username'], 'unique']
];
}
Use this way
['username', 'filter', 'filter'=>'strtolower'],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With