Welcome Guest, Not a member yet? Register   Sign In
Is there a correct way of using Flashdata? The doc seems confusing.
#3

(07-22-2020, 04:39 AM)jreklund Wrote: Personally I'm using it like this.

PHP Code:
// Helper function
if ( ! function_exists('get_flashdata'))
{
    function 
get_flashdata($name NULL$type 'success'$destroy TRUE)
    {
        if( ! empty(
$name) && isset($_SESSION[$name]) )
        {
            
$tmp $_SESSION[$name];

            if( ! 
in_array($type, ['danger','info','warning','success']) )
                
$type 'success';
            if( 
$destroy )
                unset(
$_SESSION[$name]);

            return 
'<div class="alert alert-' html_escape($type) . ' no-print">' html_escape($tmp) . '</div>';
        }
    }


Setting

PHP Code:
$_SESSION['flashdata'] = 'Whatever'

Getting

PHP Code:
<?= get_flashdata('flashdata'); ?>

Thank you. It's a nice approach.

So, is the documentation outdated?
Reply


Messages In This Thread
RE: Is there a correct way of using Flashdata? The doc seems confusing. - by castle - 07-22-2020, 09:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB