In most cases, this component is working brilliantly for me, it saves so much code in my controllers! I've come across one situation where I need to do special formatting of my flash message using helpers (e.g. the Time helper to format a date and time according to user preferences), and so I'm using a custom flash element, like:
$this->Flash->my_custom_element(null, ['params' => ['variable' => $variable]]);
And then src/Element/Flash/my_custom_element.ctp
looks something like this:
echo $this->element('BootstrapUI.Flash/default', [
'message' => __('Here is the custom message about {0}',
$this->Time->date($params['variable']->created)),
'params' => [
'class' => ['warning', 'alert', 'alert-dismissible', 'fade', 'in'],
'escape' => false,
'attributes' => ['role' => 'alert'],
],
]);
When this comes to my Ajax response handler, the _message parameter has an object with keys like so:
element: "Flash/my_custom_element"
key: "flash"
message: null
params: Object
variable: Object
(all the $variable data is here)
Seems that when you call $this->Controller->request->session()->consume
, you get back an array in such cases instead of just a message, and something further needs to be done to use the element to format this before setting it into _message.
Not sure if it makes a difference that I'm using the Friends Of Cake BootstrapUI plugin to nicely format flash output, but that works fine with all my "standard" flash messages (e.g. $this->Flash->info(__('Message goes here.'));
) Also, using this for non-Ajax requests renders the flash element correctly, so I know that much of it is okay.