Ticket #487 (new enhancement)

Opened 20 months ago

Last modified 3 months ago

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

BaseView.class.php (0.6 KB) - added by RossC0 20 months ago.
Base View
Flash.class.php (2.4 KB) - added by ross 14 months ago.
AgaviFlashMessage.class.php (4.2 KB) - added by benjamin@… 3 weeks ago.
Flash Message Class which can has different Message Types

Change History

Changed 20 months ago by RossC0

Base View

Changed 20 months ago by ross

Updated - some bug fixes ensure request data is available

Changed 19 months ago by david

  • version 0.11.0RC4 deleted
  • milestone set to 1.0

Changed 15 months ago by anonymous

Can we move initialize from BaseView? to BaseAction?? so it's possible to use $this->flash in Action and in View?

Changed 15 months ago by SunboX

some modification to Flash class:

/**

  • Checks for flash messages of type $type *
  • @return bool whether or not there is a flash messages of given type *
  • @author André Fiedler
  • @since 1.0 */

function hasFlashType($type) {

$flash = $this->getParameter('flash'); return @$flash[1] === $type;

}

/**

  • Returns the Flash Messages Array *
  • @return array an array of flash messages *
  • @author Ross Lawley
  • @since 0.11 */

function read() {

return $this->removeParameter('flash');

}

Changed 14 months ago by ross

Changed 14 months ago by ross

  • description modified (diff)

Updated Class - made standalone - so session only based. Added hasFlashType - thanks André.

Changed 11 months ago by david

  • severity changed from trivial to major

Changed 9 months ago by david

  • has_patch unset
  • milestone changed from 1.0 to 1.1

Changed 3 months ago by david

  • milestone changed from 1.1 to 1.2

Changed 3 weeks ago by benjamin@…

Flash Message Class which can has different Message Types

Add/Change #487 (Rails Style Flash Messages)

Author



Action
as new
 
Note: See TracTickets for help on using tickets.