How to check out if value is null

[font="Verdana"]Hello,

I started to create simple foundation of web application over Yii2 (kinda new person with frameworks). I faced a problem with error "Trying to get property of non-object". This happens when I give wrong username - so when the value of activationCode is null? Am I right? So I should check out if the value is null / if user exists or not. My question is: Am I right and if I am, how and where should I do that?

[/font]

Code from my UserController.php


	public function actionActivation()

	{

		$model = new ActivationForm;

		

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

		{

			$getUser = User::find()->where(['username'=>$model->username])->one();

			

			if($model->activationCode === $getUser->activationCode)

			{

				$getUser->emailActivated = 1;

				$getUser->save();

				Yii::$app->session->setFlash('activationFormSubmitted');

				return $this->refresh();

			}	

			elseif(!$model->activationCode === $getUser->activationCode)

			{

				// Yii::$app->session->serFlash('activationFormFailed');

				return $this->refresh();

			}

		}

		else {

			return $this->render('activation', [

				'model' => $model,

			]);

		}

	}

[font="Verdana"]The problem is on the 9th row:

if($model->activationCode === [color="#FF0000"]$getUser->activationCode[/color])

If you need more pieces of code, just ask.[/font]

Use before the 9 th line.

because your $getUser is Null.


if(!empty($getUser)){

//

} 


	public function actionActivation()

	{

		$model = new ActivationForm;

		

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

		{

			$getUser = User::find()->where(['username'=>$model->username])->one();

			if(!empty($getUser)) {

				if($model->activationCode === $getUser->activationCode)

				{

					$getUser->emailActivated = 1;

					$getUser->save();

					Yii::$app->session->setFlash('activationFormSubmitted');

					return $this->refresh();

				}	

				elseif(!$model->activationCode === $getUser->activationCode)

				{

					// Yii::$app->session->serFlash('activationFormFailed');

					return $this->refresh();

				}

			}

			else {

				// Username was not found flash

				return $this->refresh();

			}

		}

		else {

			return $this->render('activation', [

				'model' => $model,

			]);

		}

	}

[font=“Verdana”]Now it works, but is this what did you mean? :P Thank you so much! This Yii community is awesome. ;)[/font]