yii2 - Yii::$app->session->setFlash() is not working -
following code in sitecontroller works fine echo, not yii-method setflash(). maybe, have reconfigure config-file(main-local.php)? other ideas how keep setflash() doing job?
public function actionscript() { //a new method, programmed thomas kipp $model = new myscriptform(); $filename = 'file'; $uploadpath = yii::getalias('@uploading'); if (isset($_files[$filename])) { $file = \yii\web\uploadedfile::getinstancebyname($filename); if ($file->saveas($uploadpath . '/' . $file->name)) { echo"<script>alert('hallo');</script>"; //echo \yii\helpers\json::encode($file); } } if ($model->load(yii::$app->request->post()) && $model->validate()) { $model->fileimage = uploadedfile::getinstance($model, 'fileimage'); $model->avatar = uploadedfile::getinstances($model, 'avatar'); if ($model->fileimage) { yii::$app->session->setflash('success', 'file has been uploaded'); echo "<font size='4'><br><br><br><center>file <font color='red'> " . "$model->fileimage<font color='black'> uploaded." . "<br>it's available in folder 'uploadedfiles' </font></font color></center>"; $model->fileimage->saveas(yii::getalias('@uploadedfilesdir/' . $model->fileimage->basename . '.' . $model->fileimage->extension)); } else { yii::$app->session->setflash('error', 'there has nothing uploaded'); echo"<font size='4'><br><br><br><center>no upload-file selected.<br>" . "nothing moved folder 'uploadedfiles'</font></center>"; } if ($model->avatar) { $counter = 0; foreach ($model->avatar $avatar) { yii::$app->session->setflash('success', 'avatar has been uploaded'); echo "<font size='4'><br><center>file <font color='red'> " . "$avatar<font color='black'> uploaded." . "<br>it's available in folder 'uploadedfiles' </font></font color></center>"; $avatar->saveas(yii::getalias('@uploadedfilesdir/' . $avatar->basename . $counter . '.' . $avatar->extension)); $counter++; } } else { yii::$app->session->setflash('error', 'there has nothing uploaded'); echo"<font size='4'><br><center>no upload-file selected.<br>" . "nothing moved folder 'uploadedfiles' </font></center>"; } return $this->render('myscript', ['model' => $model]); } else { return $this->render('myscript_formular', ['model' => $model]); } }
once have assign value eg:
yii::$app->session->setflash('error', 'there has nothing uploaded');
be sure in view eg: myscript.php echo value setted
<?= yii::$app->session->getflash('error'); ?>
Comments
Post a Comment