So I'm running into a major headache with using FlashSession in Phalcon 4.0.5. Searched for a couple hours on these forums and on Google, yet I can't seem to find any help on the issue. I'm hoping someone can shed some insight on this.
I'm running a multi-module setup and currently working on the backend module. I've built a full CMS in Phalcon 3.4 and never had issues setting up and using Flash Session messages before, so it's beyond me why it isn't working now.
Here's my backend Module code to set the flashSession service:
$app->set('flashSession', function() {
$session = new Manager();
$files = new Stream(
[
'savePath' => '../core/tmp',
]
);
$session->setAdapter($files);
$escaper = new Escaper();
$flashSession = new FlashSession($escaper, $session);
return $flashSession;
});
As a note, I am using "setAdapter" rather than "setHandler", as mentioned in the docs, because using "setHandler" generates an undefined function error.
And here is my simple DB update function where I want to let the user know with a session message that the update was successful after being sent back to the main index action of the "forms" controller:
public function updateAction() {
$this->view->disable();
if($this->request->isPost()) {
// Get POST fields (sanitizes them automatically)
$formId = $this->request->getPost('form_id');
$formName = $this->request->getPost('form_name');
// Initialize Database Model and set column values for insert
$form = Forms::findFirst($formId);
$form->name = $formName;
$form->date_updated = time();
if($form->update() == false) {
$this->view->disable();
foreach ($form->getMessages() as $message) {
echo '<p>';
echo 'Message: '.$message->getMessage().'<br />';
echo 'Field: '.$message->getField().'<br />';
echo 'Type: '.$message->getType().'<br />';
echo '</p>';
}
} else {
$this->flash->success('The form has been created successfully!');
return $this->response->redirect('forms');
}
}
}
In my main index.volt layout, I am using {{ flashSession.output() }}
, but I get nothing after being redirected.
Regardless of using or removing $this->view->disable();
, the page will just redirect without the message.
I have tried to use $this->dispatcher->forward()
with the appropriate array and even then it does not display the flash message.
The output only works when removing the redirect, but obviously that's not ideal because I need to send them back to the main index action.
Any help is greatly appreciated.