vova07 / yii2-start

Yii2-Start application
Other
273 stars 115 forks source link

Some caution with the use of Module->getInstance() #137

Closed nunomaduro closed 9 years ago

nunomaduro commented 9 years ago

I think that getInstance function should not be used in your modules. Because for example if I want to create my own modules that extend from your modules that simple function will cause an exception. Because your module is not init in my main.php, only my module.

For example:

/**
 * @inheritdoc
 */
public function rules()
{
    return [
        // Name
        ['name', 'match', 'pattern' => Module::getInstance()->patternName],
        // Surname
        ['surname', 'match', 'pattern' => Module::getInstance()->patternSurname]
    ];
}

Maybe you should put like this:

/**
 * @inheritdoc
 */
public function rules()
{
    return [
        // Name
        ['name', 'match', 'pattern' => '/^[a-zа-яё]+$/iu'],
        // Surname
        ['surname', 'match', 'pattern' => '/^[a-zа-яё]+(-[a-zа-яё]+)?$/iu']
    ];
}
vova07 commented 9 years ago

Yes, I know, and I'm completely agree with you. It will be fixed in next releases. Thanks!

nunomaduro commented 9 years ago

I already made a pull request to yii2-start-users-module to remove that method. After you aprove you can close this.

vova07 commented 9 years ago

Thank you!