I set up a little test to have a play with this...
I created a Controller (Home) to set up a flashData value with a link to another controller (Page) that sets up a second flashData value and attempts to displays both of them.
The Home Controller (app\Controllers\Home.php)
class Home extends BaseController
{
protected $session;
public function __construct() {
$this->session = \Config\Services::session();
}
public function index()
{
$this->session->setFlashdata('errmsg_1','Error Message 1');
echo '<a href="page">Click here to View the Flash Data</a><br>';
}
}
The Page Controller (app\Controllers\Page.php)
class Page extends BaseController {
protected $session;
public function __construct() {
$this->session = \Config\Services::session();
}
public function index() {
echo __LINE__ . ' ' . __CLASS__ . ' ' . __METHOD__;
$this->session->setFlashdata('errmsg_2','Error Message 2');
return redirect()->to('/page/register');
}
public function register() {
echo __LINE__ . ' ' . __CLASS__ . ' ' . __METHOD__;
$page['error_message_1'] = $this->session->getFlashdata('errmsg_1');
$page['error_message_2'] = $this->session->getFlashdata('errmsg_2');
echo view('page_view', $page);
}
}
And the View (app\Views\page_view.php)
<?php
/**
* @var string $error_message_1
* @var string $error_message_2
*/
echo '<br>';
echo 'Error 1 :';
echo ($error_message_1) ? $error_message_1 : 'I am Null'; // Expect this to be NULL?
echo '<br>';
echo 'Error 2 :';
echo ($error_message_2) ? $error_message_2 : 'I am Null'; // This should appear
echo '<br><a href="/home">Go Back Home</a><br>';
So the Home Controller loads up the FlashData for "errmsg_1" with a link to take us to the Page Controller.
Once at the Page Controller, the index sets an additional errmsg_2 and performs a redirect to the register method.
So after clicking the link from the Home Controller we arrive at the Page Controller which displays...
17 App\Controllers\Page App\Controllers\Page::register
Error 1 :I am Null
Error 2 :Error Message 2
Go Back Home
And on performing a Refresh on the Page Controller we get...
17 App\Controllers\Page App\Controllers\Page::register
Error 1 :I am Null
Error 2 :I am Null
Go Back Home
So the redirect does work using flashData.
The only downside is that you have to pass the flashdata value as a variable into the view to display it.