CakePHP4 - Use HTML in Flash Messages

Show HTML in Flash Messages in CakePHP4

This example shows you how to add an HTML link to your flash messages.

$impersonatingUser = $this->Authentication->getIdentity()->username;
            $this->Flash->info(sprintf('You are currently impersonating user %s.  When you wish to revert back to %s, <a href="%s">Click Here</a>', 
                h($impersonatingUser), //first %s variable
                h($session->read('impersonate')->username), //second %s variable
                h($session->read('impersonate')->username)), 
                ['escape' => false] //allow html );

 

 

Share this Post