• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Message Handling Library

Hey guys,

i thought i would post a simple message handling library i came up with. Nothing special but maybe a good foundation for something more involved.

currently it has multiple states of a message (success, warn & error).

Will be making more improvements soon!

should be located in: application/libraries/Message_handler.php

probably a good idea to autoload in autoload.php

code below:

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Message_handler {

    var $CI;
    function Message_handler() {
        $this->CI =& get_instance();
        log_message('debug', 'Message Handler initialized.');
    //show and remove (page scope only)
    function display() {
        $msg = $this->CI->session->userdata('message');
        return $msg;
    // add a message for display
    function add($msg,$type = 'success') {
        switch($type) {
            case 'success':
                $output  = '<div id="success">';
            case 'error':
                $output  = '<div id="error">';
            case 'warning':
                $output  = '<div id="warning">';    
        $output .= '<div class="item">' . $msg . '</div>';
        $output .= '</div>';



in your controller simply use line to add a message:
$this->message_handler->add('Your account has been created.');

to display a message use this code, in your view or passed from a controller:

cheers all (codeigniter FTW)

hmm that looks just like flashmsgs that you can use in sessions Wink
just check the svn for the new CI updates.

ill have to check that out


[eluser]Craig A Rodway[/eluser]
That's a nice idea, thanks! Smile

This might be useful for styling your boxes: Create a valid CSS alert message (read the comments for some discussion on correct CSS usage though).

Mu current method for these sort of messages is like this:

4 view files (error, info, warning, question) in a directory called msgbox. This is my /views/msgbox/error.php file:

<p class="msgbox error">&lt;?php echo $vars; ?&gt;</p>

Although this is not the traditional use for the variable passing to views, it allows me to do this in my controllers and/or views:

// Controller:
$body['content'] = $this->load->view('msgbox/error', 'An error occured.', True);

// View:
$this->load->view('msgbox/error', 'An error occured');

to display a message use this code, in your view or passed from a controller:

Just want to make a quick correction to the code above. It should be:

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.