Fork me on GitHub

Nibble Development

Nibble Development

PHP classes and libraries for developers

Nibble Flash Messaging PHP class

What is Nibble flash messaging?

Nibble flash messaging is a PHP class that allows messages to be created that are then displayed to the user using a JQuery script by Tim Benniks and a little extra JQuery added by us. Nibble flash messaging is a very simple and easy to use class, there are 2 types of messages, regular messages which are displayed on the same page they are created, or flash messages which are displayed on the next page load. The flash messages are useful for sites such as blogs where, for example, the “create post” PHP script adds a new post to the database and then redirects to a new page. Using the flash message, the create post script can add a message that will be displayed on the page that the user is redirected to. The Nibble framework makes use of this PHP class.

Simple overview

The simplest flash message example requires an instance of the flash class and a message to add. The below example creates a regular message that has the text “Simple message example” and an identical flash message:

The messages can then be rendered to the page using the php method “render” from the flash class:

Flash/Regular message options

Flash and regular message are created using the same set of arguments, only the PHP method call differentiates the message type to be added. Although the flash class can create both flash and regular messages with just one supplied argument, there are three optional, additional arguments that allow the message content and behaviour to be customised.

  1. Message content:  The first argument as shown above is a string that represents the content of the message to be shown to the user.
  2. Message title: The second argument in the message function is the message title value. This value is a string that is outputted to the message in heading tags.
  3. Message lifetime: This value represents the life time of the message in milliseconds. I.e 1000 represents a lifetime of 1 second. The default lifetime is 5 seconds.
  4. Sticky message: The fourth argument represents whether or not the message is sticky, the value is either True or False, True means the message is sticky and will thus stay on the page until the user clicks the close icon on it, False means the message will obey the lifetime value supplied in the previous argument.
  5. Message type: The final argument adds a string as a CSS class to the message so that different message types can be styled differently, for example, error messages could be red

Below is an example of a flash and regular message using the additional PHP arguments, it should be noted, as stated earlier, :

Troubleshooting Nibble Flash Messaging

There are a couple of instances we can think of that might cause issues in your code when trying to use the Nibble flash messaging. If your case is not one of the issue below please feel free to contact us for a few pointers.

I can make regular messages work but not the flash ones

To remember the flash messages created in the script, the Nibble flash class requires a session variable, make sure that the snippet below is included above, preferably at the start of your script, the include line for flash.class.php:

I get an error, JQuery is not defined

The client side code in notice.js requires the JQuery library in order to work, make sure to include this snippet above the call for notice.js in your HTML (note that the below also calls JQuery UI which may not be necessary for your application):


Luke Rotherfield

Freelance PHP Developer
is a PHP developer dedicated to writing the most awesome liraries for his fellow devs :) enjoy

Latest posts by Luke Rotherfield (see all)

Leave a Comment