3

I was searching for password strength meter for Yii2. I found this article for Yii1. I saw protected directory mention there. I'm unable to find this folder. Is it available in Basic Application Template or Advanced Application Template?

arogachev
  • 31,868
  • 6
  • 105
  • 113
Nana Partykar
  • 10,175
  • 8
  • 43
  • 73

2 Answers2

5

There is no protected directory in Yii2 (neither in basic nor in advanced application template).

Where to place your custom validator - it's up to you.

I'd recommend components/validators folder.

Here is the part of the official guide covering custom validation for Yii2.

Also take a look at this extension, maybe it already covers your needs, so you don't have to reinvent the wheel.

arogachev
  • 31,868
  • 6
  • 105
  • 113
  • yii2-app-basic/vendor/yiisoft/yii2-gii/components folder is there. In this folder, can i create 'validators' folder ? And, if i declare ' passwordStrength.php' page inside validators folder, will i have to write something new to extend class name in this passwordStrength.php page. Sorry Mr @Arogachev. I'm new to it. So, asking silly questions. Don't mind. – Nana Partykar Sep 21 '15 at 11:41
  • It's OK. We all learn. You should not modify any files under `vendor` folder. And Gii is for completely different purposes. Create inside application root folder. – arogachev Sep 21 '15 at 11:43
  • Ok. Thanks Mr Arogachev. – Nana Partykar Sep 21 '15 at 11:44
  • As for better understanding, see the official guide link I provided. Yii2 have many things at common with Yii1, but at the same time different in many things. – arogachev Sep 21 '15 at 11:45
4

protected forder is for Yii1

Yii2 Not have this folder

You can use this example code in your model

public function rules()
{
    return [
        ['password', 'checkPassword'],

        // other rules
    ];
}

public function checkPassword($attribute, $params)
{
    // no real check at the moment to be sure that the error is triggered
    if(password != OK )
         $this->addError($attribute, 'Your password not valid');
}
Amir Mohsen
  • 795
  • 8
  • 21