public function getFlash($key = null)
    {
        $messages = $flash = '';

        if (!Session::has('flashMessages')) {
            return false;
        }

        $flashArray = Session::get('flashMessages');

        // Check $key is valid flash type
        if (in_array($key, $this->validFlashTypes)) {
            if (isset($flashArray[$key])) {
                foreach ($flashArray[$key] as $msg) {
                    $messages .= '<p>'.$msg."</p>\n";
                }
            }

            $flash .= sprintf(
                $this->flashWrapper,
                strtolower(Inflector::getClassName($this->class)),
                $key,
                $messages
            );

            // clear the viewed messages from browser
            $this->clearViewedMessages($key);

            // Print ALL queued messages
        } elseif (is_null($key)) {
            foreach ($flashArray as $key => $msgArray) {
                $messages = '';
                foreach ($msgArray as $msg) {
                    $messages .= '<p>'.$msg."</p>\n";
                }

                $flash .= sprintf($this->flashWrapper, strtolower($this->class), $key, $messages);
            }

            // clear already viewed messages
            $this->clearViewedMessages();

            // Invalid message type
        } else {
            return false;
        }

        return $flash;
    }