On one page there is registration and authorization. When authorized, everything is fine, comes home and I can go out, but when I try to register, the same authorization occurs, i.e. Works one scenario. Tried to make two scenarios. Either I do not understand how it works correctly, or I am somewhere else in another place.
Action in the controller
public function actionsignlog () {
$ this- & gt; layout = 'log';
If (! Yii :: $ App- & gt; User- & gt; isguest) {
Return $ this- & gt; gohome ();
}
$ LoginModel = new loginform ();
$ SignUpModel = new signupform ();
If ($ LoginModel- & gt; load (Yii :: $ App- & gt; Request- & gt; post ()) & amp; & amp; $ loginmodel- & gt; login ()) {
Return $ this- & gt; goback ();
} else {
Return $ this- & gt; render ('SignLog', [
'loginmodel' = & gt; $ LoginModel,
'SignUpModel' = & gt; $ signupmodel
]);
}
}
Login form in View
& lt;? php $ form = ActiveForm :: Begin (['id' = & gt; 'login-form']) ; ? & gt;
& lt;? = $ form- & gt; field ($ loginmodel, 'username') - & gt; textinput (['autofocus' = & gt; true])? & GT;
& lt;? = $ Form- & gt; field ($ loginmodel, 'password') - & gt; passwordinkut ()? & gt;
& lt;? = $ form- & gt; field ($ LoginModel, 'RememberMe') - & gt; checkbox ()? & gt;
& lt; div style = "color: # 999; margin: 1em 0" & gt;
If you forgot your password, you can & lt;? = HTML :: A ('Reset', ['Site / Request-Password-Reset'])? & GT; his
& lt; / div & gt;
& lt; div class = "Form-Group" & gt;
& lt;? = HTML :: SubmitButton ('Log in', ['Class' = & gt; 'BTN BTN-PRIMARY', 'NAME' = & GT; 'Login-Button'])? & gt;
& lt; / div & gt;
& lt;? PHP ActiveForm :: End (); ? & gt;
Registration form in View
& lt;? php $ form = activeform :: begin (['id' = & gt; 'signup-form']) ; ? & gt;
& lt;? = $ Form- & gt; field ($ signupmodel, 'username') - & gt; textinput (['autofocus' = & gt; true])? & gt;
& lt;? = $ Form- & gt; field ($ signupmodel, 'email')? & gt;
& lt;? = $ form- & gt; field ($ signupmodel, 'password') - & gt; passwordinkut ()? & gt;
& lt;? = HTML :: SubmitButton ('Register', ['Class' = & gt; 'BTN BTN-PRIMARY', 'NAME' = & GT; 'Signup-Button'])? & gt;
& lt;? PHP ActiveForm :: End (); ? & gt;
Answer 1, Authority 100%
You do not use the registration model, this is the problem. Make this:
public function actionsignlog () {
$ this- & gt; layout = 'log';
If (! Yii :: $ App- & gt; User- & gt; isguest) {
Return $ this- & gt; gohome ();
}
$ LoginModel = new loginform ();
$ SignUpModel = new signupform ();
If ($ LoginModel- & gt; load (Yii :: $ App- & gt; Request- & gt; post ()) & amp; & amp; $ loginmodel- & gt; login ()) {
Return $ this- & gt; goback ();
} ELSE if ($ signupmodel- & gt; load (Yii :: $ App- & gt; Request- & gt; post ()) & amp; & amp; $ signupmodel- & gt; signup ()) {// or the one that you use for registration
Return $ this- & gt; goback ();
}
Return $ this- & gt; render ('SignLog', [
'loginmodel' = & gt; $ LoginModel,
'SignUpModel' = & gt; $ signupmodel
]);
}