Skip to content

yiier/yii2-invite-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

invite code for Yii2

Latest Stable Version Total Downloads Latest Unstable Version License

invite code for Yii2

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yiier/yii2-invite-code "*"

or add

"yiier/yii2-invite-code": "*"

to the require section of your composer.json file.

Usage

mirage database

$ php yii migrate --migrationPath=@yiier/inviteCode/migrations/

change config

change console\config\main.php

'params' => $params,
...
'controllerMap' => [
    'gcode' => [
        'class' => 'yiier\inviteCode\GCodeController',
    ]
]

console

$ php yii gcode 200

or

$ php yii gcode

change form view signup.php

// ...
<?= $form->field($model, 'password')->passwordInput() ?>

<?= $form->field($model, 'inviteCode')->textInput() ?>
// ...

change SignupForm.php

// ...
public $inviteCode;


// ...
public function rules()
{
    return [
        // ...
        ['inviteCode', 'required'],
        ['inviteCode', 'yiier\inviteCode\CodeValidator'],
    ];
}

// ...
public function signup()
{
    // ...
    
    // return $user->save() ? $user : null;
    // after change
    if ($user->save()) {
        InviteCode::useCode($this->inviteCode, $user->id);
        return $user;
    }
    return null;
}

About

Invite Code for Yii2 (邀请码)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages