I built my flashmessager function in the following steps
- run composer command( and choose to inject configuration in modules.config.php):
composer require laminas/laminas-mvc-plugin-flashmessenger
- add message in an action like
public function qqcallbackAction()
{
$request = $this->getRequest();
$identityArr = $this->plugin('auth')->getIdentity($request);
if ($identityArr) return $this->redirect()->toRoute('user', ['action' => 'profile']);
$response = $this->getResponse();
/** @var MembersPlugin $membersPlugin */
$membersPlugin = $this->plugin('members');
$errMsg = $membersPlugin->qqcallback($request, $response);
if ($errMsg)
{
$this->flashMessenger()->addSuccessMessage('紫霞喊你'); //addSuccessMessage or addErrorMessage both not work.
return $this->redirect()->toRoute('user', ['action' => 'thirdguide']);
}
return $this->redirect()->toRoute('user', ['action' => 'profile']);
}
- render the message in the view script of another action(thirdguide.phtml):
<!--99999999999999999999999999-->
<?= $this->flashMessenger()->render('success'); //success or error both nothing show ?>
<!--99999999999999999999999999-->
but !!!
if i place the message render inside the action its own view script, it works!!
that means when I place the clothest above code inside qqcallback.phtml, you know it is the same action which I add the message there.
I strictly following the official document Basic Usage - laminas-mvc-plugin-flashmessenger - Laminas Docs
It is session based, so I pasted my session configuration here for reference (in global.php).
retrun [
// other configuration like db here
'session_containers' => [
Laminas\Session\Container::class,
],
'session_config' => [
'cache_expire' => 86400 * 30,
'cookie_httponly' => true,
'cookie_lifetime' => 86400 * 30,
'gc_maxlifetime' => 86400 * 30,
'name' => 'llren',
'remember_me_seconds' => 86400 * 30,
'use_cookies' => true,
],
'session_storage' => [
'type' => Laminas\Session\Storage\SessionArrayStorage::class,
],
'session_manager' => [
'validators' => [
Laminas\Session\Validator\RemoteAddr::class,
Laminas\Session\Validator\HttpUserAgent::class,
],
],
];
any body can help me out? So appreciated! I have been working on that for a whole afternoon.