Code Monkey home page Code Monkey logo

codeigniter-message-library's Introduction

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");

codeigniter-message-library's People

Contributors

jenssegers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

codeigniter-message-library's Issues

Hello

Is there any chance that you could pass the repository to me? Maybe for the moment there aren't any big changes to be made to the library (to be honest, none...), but maybe in the future there will be the need for such changes.

Internationalization

This is a request not a bug!
Pass as the first parameter a language files for purposes of internationalization, like:

$this->messages->add( $this->lang->line('error_permission_denied'), 'error');

Count bug

Line 76

if (array_key_exists($type, $messages))
    return $messages[$type];

Should be

if (array_key_exists($type, $messages))
    return count($messages[$type]);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.