#487: Rails Style Flash Messages
-------------------------+--------------------------------------------------
Reporter: RossC0 | Owner: david
Type: enhancement | Status: new
Priority: normal | Milestone: 1.0
Component: _OTHER_ | Version:
Severity: trivial | Resolution:
Keywords: Flash |
-------------------------+--------------------------------------------------
Old description:
> 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 ==
> * !BaseWebResponse - On send of headers it calls the flash classes
> shutdown
> * !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. Has a shutdown function to write any unused messages back
> to the session.
>
> == 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.
New description:
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.
Comment (by ross):
Updated Class - made standalone - so session only based.
Added hasFlashType - thanks André.
--
Ticket URL: <http://trac.agavi.org/ticket/487#comment:5>
Agavi <http://www.agavi.org/>
An MVC Framework for PHP5
_______________________________________________
Agavi Tickets Mailing List
[email protected]
http://lists.agavi.org/mailman/listinfo/tickets