Loses session after redirect

Here is my code …




$clockInSignInForm = new ClockInSignInForm;

			

			if($clockInSignInForm->load(Yii::$app->request->post()) && $clockInSignInForm->validate()) {

				

				Yii::$app->user->logout();

								

				$property = Property::find()->andwhere(["clockInUsername" => $clockInSignInForm->username])->one();

																

				Yii::$app->user->login($property);

								

				return $this->redirect(["clock-in/"]);

				

			}

				

			$clockInSignInForm->password = null;

			

			return $this->render("create", [

				

				"models" => [

					

					"clockInSignInForm" => $clockInSignInForm

					

				]

				

			]);



If I echo out the Yii::$app->user->id after login it works, but on the page after if I echo it, it does not work.

I have tried echoing session data before and after however it echoes before redirect but not after.

The code use to work so I do not know why it would not be working now. I have tried clearing browser cache and still not working.

The page after redirect is literally just an action with the echo in it and that is it.

Ok found out why its because identity class is set to user in config.

However this is using property model as user.

I want to use both for different logins / purposes how is this possible?

Ok I have set it up like this …




'user' => [

            'identityClass' => 'app\models\User',

            'enableAutoLogin' => true,

	     'loginUrl' => ['sign-in/create']

        ],

        'property' => [

	     'class' => 'yii\web\User',

            'identityClass' => 'app\models\Property',

            'enableAutoLogin' => true,

	     'loginUrl' => ['clock-in-sign-in/create']

        ],



User works but property does not.

Both configs, models and controllers are set up the same for them.

But property does not work after redirect.

But with property session is destroyed after redirect.

Hi,

It is OK now, it works the way I described above in the post.

If you want to get this working, just do what I said in the above post.

James.