invite code for Yii2
, (*1)
invite code for Yii2, (*2)
Installation
The preferred way to install this extension is through composer., (*3)
Either run, (*4)
php composer.phar require --prefer-dist yiier/yii2-invite-code "*"
or add, (*5)
"yiier/yii2-invite-code": "*"
to the require section of your composer.json
file., (*6)
Usage
mirage database, (*7)
$ php yii migrate --migrationPath=@yiier/inviteCode/migrations/
change config, (*8)
change console\config\main.php
, (*9)
'params' => $params,
...
'controllerMap' => [
'gcode' => [
'class' => 'yiier\inviteCode\GCodeController',
]
]
console, (*10)
$ php yii gcode 200
or, (*11)
$ php yii gcode
change form view signup.php
, (*12)
// ...
= $form->field($model, 'password')->passwordInput() ?>
= $form->field($model, 'inviteCode')->textInput() ?>
// ...
change SignupForm.php
, (*13)
// ...
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;
}