Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Store and display error or information messages to display on the current page or next page
PHP
branch: master
Failed to load latest commit information.
config Fix for issue reported by jellysandwich
libraries Bugfix
README.md Documentation
spark.info Bugfix

README.md

CodeIgniter Message Library

You can use this library to store and retrieve your error or information messages whenever you want. The messages are cleared when you retrieve them, so they remain available even after a redirect!

Usage

To install the library, place it inside your libraries folder and load it using $this->load->library("messages");

Or use the spark.

Adding messages

To add messages for later display you can add them to a specific message group using:

$this->messages->add("An error has occurred", "error");
$this->messages->add("Thank you for registering", "success");
$this->messages->add("Please not this message", "message");

Displaying messages

The added messages stays available until you retrieve them. So if you would add them in a specific controller and then redirect, the messages would still be available. This is especially handy for displaying error messages when an action has failed.

$messages = $this->messages->get();

This will return an array to be used like this:

$all = $this->messages->get();
    foreach($all as $type=>$messages)
        foreach($messages as $message)
            echo $type.': '.$message.'<br>';

If you only want one specific type of message you can use:

$messages = $this->messages->get("error");

So that you can display them using:

$errors = $this->messages->get("error");
    foreach($errors as $error)
        echo 'error: '.$error.'<br>';

If at any point you want to know how many messages are stored you can use:

$errors = $this->messages->count("error");
$all = $this->messages->count();

The stored messages are cleared when you retrieve them using get(), but if you want to manually clear them you can use:

$this->messages->clear();
$this->messages->clear("error");
Something went wrong with that request. Please try again.