Session->read('messages'); $cMessages = (array)Configure::read('messages'); if (!empty($cMessages)) { $messages = (array)Hash::merge($messages, $cMessages); } $html = ''; if (!empty($messages)) { $html = '
'; if ($types) { foreach ($types as $type) { // Add a div for each message using the type as the class. foreach ($messages as $messageType => $msgs) { if ($messageType !== $type) { continue; } foreach ((array)$msgs as $msg) { $html .= $this->_message($msg, $messageType); } } } } else { foreach ($messages as $messageType => $msgs) { foreach ((array)$msgs as $msg) { $html .= $this->_message($msg, $messageType); } } } $html .= '
'; if ($types) { foreach ($types as $type) { $this->request->session()->delete('messages.' . $type); Configure::delete('messages.' . $type); } } else { $this->request->session()->delete('messages'); Configure::delete('messages'); } } return $html; } /** * Outputs a single flash message directly. * Note that this does not use the Session. * * @param string $message String to output. * @param string $type Type (success, warning, error, info) * @param bool $escape Set to false to disable escaping. * @return string HTML */ public function message($msg, $type = 'info', $escape = true) { $html = '
'; if ($escape) { $msg = h($msg); } $html .= $this->_message($msg, $type); $html .= '
'; return $html; } /** * Formats a message * * @param string $msg Message to output. * @param string $type Type that will be formatted to a class tag. * @return string */ protected function _message($msg, $type) { if (!empty($msg)) { return '
' . $msg . '
'; } return ''; } /** * Add a message on the fly * * @param string $msg * @param string $class * @return void */ public function addTransientMessage($msg, $class = null) { FlashComponent::transientMessage($msg, $class); } }