Ticket #487 (new enhancement)
Rails Style Flash Messages
| Reported by: | RossC0 | Owned by: | david |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.2 |
| Component: | _OTHER_ | Version: | |
| Severity: | major | Keywords: | Flash |
| Cc: | Patch attached: | no |
Description (last modified by ross) (diff)
I think this is something that is going to be considered in version 1 or beyond.
However, if you can't wait heres an example of how you can easily achieve this.
Extending core classes
- BaseView - Get the Flash Class and automatically sets to Attribute for template
Flash Class
- Simple parameter holder, gets any flash messages from session in the constructor.
Usage
Before the View
- Either pass in the $rd and in the view write to a message - could be automated
- Add to the session i.e.:
$storage->write('agavi.org.flash', array($message, $style));
View
$this->flash->write($message, $style);
Master Template
<?php if ($t['flash']->hasFlash()): ?> <?php $flash = $t['flash']->read();?> <div class='flash <?php echo $flash['1']; ?>'><?php echo $flash['0']; ?></div> <?php endif; ?>
Caveats
- Flash messages are destroyed as soon as the flash->read(); method is called.
- Flash messages will live in the session until flash->read() is called.
- Only allows a single flash message.
- Not integrated so mulitple interfaces i.e. add via the session before the view and via $this->flash in the view.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

