/** * Loads UserPreferences model from session or creates new one * @return UserPreferences */ public static function preferences() { if (static::$_cachedPreferences === null) { $model = new UserPreferences(); $model->load([]); $model->validate(); $attributes = Yii::$app->session->get('UserPreferencesModel'); if (isset($attributes) === true) { $model->setAttributes($attributes); } static::$_cachedPreferences = $model; } return static::$_cachedPreferences; }