I wonder if the problem is related to autoloading. Iiuc, PHP needs the object’s class to be loaded or it cannot unserialize it. I suppose Yii unserializes session data early but isn’t it rather lazy about loading classes? If this is the problem then there should be a PHP error.
Btw, the application component Yii::$app->session should be active when actionMap() runs so invoking $sessionPHP->open() is unnecessary and a bit confusing.
Maybe @tklustig is destroying session data by himself somewhere else, because he was unnecessarily calling Session::destroy() in another context (Yii::$app->request->post() is always empty). But I really don’t know for sure.
BTW, I would still hesitate to store an ActiveDataProvider instance into session even if it would be possible. Simple objects including Model and ActiveRecord might be OK, but it looks dangerous to me to store/restore a complicated object into/from session.
I don’t destroy whole session any more, I am removing special session element instead. Nevertheless, second time, I will push on Css, respectively glyphicon icon, sessions will be empty, both, as already having shown up. So,
if (empty($sessionPHP['dataProvider']) || empty($sessionPHP['searchModel']))
You mean that the session entries are empty when you call termin/map action from the map button?
I’d like to see the controller code where you show the gridview and set the variables to the session.
I already posted all code being invloved in at my first post. As well as setting variables to session, as also rendering Grid(index), using these sessions!
public function actionIndex($id = NULL) {
//keine Termine vorhanden?
$countTermine = Besichtigungstermin::find()->count('id');
if ($countTermine == 0) {
$link = \Yii::$app->urlManagerBackend->baseUrl . '/home';
$zusatz = '?message=Es+exisitieren+noch+keine+Besichtigungstermine++in+der+Datenbank.+Steigern+Sie+Ihre+Kundenaqkuise%21';
return $this->redirect($link . $zusatz);
}
$searchModel = new TerminSearch();
/* sofern eine Maklerid übergeben wurde, zeige nur diejenigen Records an, deren PK als FK(besichtigungstermin_id)
in adminbesichtigungkunde vorhanden ist */
$arrayOfFk = array();
if ($id != null) {
$modelAdminBesKu = Adminbesichtigungkunde::find()->all();
foreach ($modelAdminBesKu as $item) {
if ($item->admin_id == $id)
array_push($arrayOfFk, $item->besichtigungstermin_id);
}
/* sofern das Array nicht leer, lege eine Session an, da nur so der Wert an die Methode actionLink(), die in der index über eine
Anonymous Function aufgerufen wird, übergeben werden kann
*/
if (!empty($arrayOfFk)) {
$searchModel->foreignKeys = $arrayOfFk;
$sessionPHP = Yii::$app->session;
$sessionPHP->open();
$sessionPHP['foreignKeys'] = $arrayOfFk;
$sessionPHP->close();
}
}
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if (!$sessionPHP->isActive)
$sessionPHP->open();
$sessionPHP['searchModel'] = $searchModel;
$sessionPHP['dataProvider'] = $dataProvider;
$sessionPHP->close();
//wurden keine Besichtigungstermine gefunden, aber danach gesucht?
if ($id != null && empty($arrayOfFk)) {
$message = 'Für diesen Makler wurde noch kein Besichtigungstermin festgelegt. Wir raten zur umgehender Kündigung dieser faulen Ratte.';
$this->message($message, 'Warnung!', 2000, Growl::TYPE_WARNING);
return $this->redirect(['/termin/preselect', 'message' => $message]);
//wurden Besichtigungstermine gefunden, dann erstelle den Header für den entsprechenden Makler(intern:User)
} else if ($id != null && !empty($arrayOfFk)) {
$makler = User::findOne(['id' => $id])->username;
$header = "Besichtigungstermine für Makler $makler anzeigen";
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'header' => $header
]);
//nix traf zu? Dann render die index ohne Einschränkungen
} else {
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider
]);
}
}
Well, that’s shaking me. If u can’t fix bug, nobody will be able fixing it. Because of that, I decided reimplementing code of creating searchModel and dataProvider in actionMap in order to render index again, which is only comromise solution.
I know. But it makes me nervous when an action method is directly managing the session when that’s the application component’s responsibility. Knowing that such a line does no harm is ok but even better is not needing to know.