Session not stored

Hello,

i have create a BaseController where i want store into the init method a variable into the session:


class BaseController extends Controller {

	public function init() {

		$session = Yii::$app->session;

		$request = Yii::$app->request;

		if (($clientid=(intval($request->get('clientid'))!=null))&&Clients::clientIdExists($clientid)) {

			if (!$session->isActive) {

				$session->open();

			}

			$session->set('clientid',$clientid);

			$session->close();

		}

		parent::init();

	}

}

My problem is, that the session-var isn’t write into the session. For example in a view-file:




$session = Yii::$app->session;

print_r($session->has('clientid')); // echoed true

print_r($session->get('clientid')); // echoed also true???



I don’t understand what goes wrong here. Everyone have an idea?

You are setting a boolean value to $clientid. Check the parentheses carefully.




if ( ($clientid=intval($request->get('clientid'))) !=null && Clients::clientIdExists($clientid)) {



Thanks @softark, that was the failure.