|
|
@@ -25,12 +25,63 @@ class FlashHelper extends Helper {
|
|
|
|
|
|
use StringTemplateTrait;
|
|
|
|
|
|
+/**
|
|
|
+ * Default config for this class
|
|
|
+ *
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
protected $_defaultConfig = [
|
|
|
'templates' => [
|
|
|
'flash' => '<div id="{{key}}-message" class="message-{{class}}">{{message}}</div>'
|
|
|
]
|
|
|
];
|
|
|
|
|
|
+/**
|
|
|
+ * Used to render the message set in FlashCompnet::set()
|
|
|
+ *
|
|
|
+ * In your view: $this->Flash->out('somekey');
|
|
|
+ * Will default to flash if no param is passed
|
|
|
+ *
|
|
|
+ * You can pass additional information into the flash message generation. This allows you
|
|
|
+ * to consolidate all the parameters for a given type of flash message into the view.
|
|
|
+ *
|
|
|
+ * {{{
|
|
|
+ * echo $this->Flash->out('flash', ['class' => 'new-flash']);
|
|
|
+ * }}}
|
|
|
+ *
|
|
|
+ * The above would generate a flash message with a custom class name. Using $attrs['params'] you
|
|
|
+ * can pass additional data into the element rendering that will be made available as local variables
|
|
|
+ * when the element is rendered:
|
|
|
+ *
|
|
|
+ * {{{
|
|
|
+ * echo $this->Flash->out('flash', ['params' => ['name' => $user['User']['name']]]);
|
|
|
+ * }}}
|
|
|
+ *
|
|
|
+ * This would pass the current user's name into the flash message, so you could create personalized
|
|
|
+ * messages without the controller needing access to that data.
|
|
|
+ *
|
|
|
+ * Lastly you can choose the element that is rendered when creating the flash message. Using
|
|
|
+ * custom elements allows you to fully customize how flash messages are generated.
|
|
|
+ *
|
|
|
+ * {{{
|
|
|
+ * echo $this->Flash->out('flash', [element' => 'my_custom_element']);
|
|
|
+ * }}}
|
|
|
+ *
|
|
|
+ * If you want to use an element from a plugin for rendering your flash message you can do that using the
|
|
|
+ * plugin param:
|
|
|
+ *
|
|
|
+ * {{{
|
|
|
+ * echo $this->Session->flash('flash', [
|
|
|
+ * 'element' => 'my_custom_element',
|
|
|
+ * 'params' => ['plugin' => 'my_plugin'])
|
|
|
+ * ]);
|
|
|
+ * }}}
|
|
|
+ *
|
|
|
+ * @param string $key The [Message.]key you are rendering in the view.
|
|
|
+ * @param array $attrs Additional attributes to use for the creation of this flash message.
|
|
|
+ * Supports the 'params', and 'element' keys that are used in the helper.
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
public function out($key = 'flash', $attrs = []) {
|
|
|
$flash = $this->request->session()->read("Message.$key");
|
|
|
$this->request->session()->delete("Message.$key");
|