CodeIgniter Forums
Status Library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Status Library (/showthread.php?tid=28056)



Status Library - El Forum - 02-28-2010

[eluser]Alfredor[/eluser]
Hello everyone,
I was looking into something to output status messages easy and quickly so I came to this:
config/status.php
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
$config['success_start'] = "<div class='success'>";
$config['sucess_end'] = "</div>";
$config['warming_start'] = "<div class='warming'>";
$config['warming_end'] = "</div>";
$config['failed_start'] = "<div class='failed'>";
$config['failed_end'] = "</div>";
$config['null_start'] = "<div>";
$config['null_end'] = "</div>";
/* End of file status.php */
/* Location: ./system/application/config/status.php */

library/status.php
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* Status Class
*
* Status Message Library For CodeIgniter.
*
* @author        Alfredo Rivera
* @version        1.0
*/

class Status
{
    /* Load Constructor Function */
    function Status()
    {
    $this->ci =& get_instance(); //Getting Instance.
    log_message('debug','Status Library Initialized'); //Log Message.
    $this->success_start = $this->ci->config->item('success_start'); //Load Success Opening Tag.
    $this->success_end = $this->ci->config->item('sucess_end'); //Load Success Closing Tag.
    $this->warming_start = $this->ci->config->item('warming_start'); //Load Warming Opening Tag.
    $this->warming_end = $this->ci->config->item('warming_end'); //Load Warming Closing Tag.
    $this->failed_start = $this->ci->config->item('failed_start'); //Load Failed Opening Tag.
    $this->failed_end = $this->ci->config->item('failed_end'); //Load Failed Closing Tag.
    $this->null_start = $this->ci->config->item('null_start'); //Load Null Opening Tag.
    $this->null_end = $this->ci->config->item('null_end'); //Load Null Closing Tag.
    }
    
    /*Function set()
    **3 default values are within the library: success, warming, failed.
    **Opening and Closing tags are found in config/status.php
    **2 parameters can be defined for this function, the content of the actuall status,
    **and the type in this case the class defined on your css file.
    **Usage Example: &lt;?php echo $this->status->set('Invalid File Uploaded','warming'); ?&gt;
    **This will output: <div class='warming'>Invalid File Uploaded</div>
    */
    function set($content = NULL,$type = NULL)
    {
    if($type == 'success'){return $this->success_start . $content . $this->success_end;}
    if($type == 'warming'){return $this->warming_start . $content . $this->warming_end;}
    elseif($type == 'failed'){return $this->failed_start . $content . $this->failed_end;}
    elseif($type == NULL){return $this->null_start . $content . $this->null_end;}
    else {return "Invalid Status Set";}
    }
    
    /*Function set_redirection()
    **1 default value is within the library: Redirection time is equal to 0.
    **2 parameters can be defined for this function, the destination to where the page is going
    **to be redirected and the time it takes to begin the redirection.
    **Usage Example: &lt;?php echo $this->status->set_redirection('admin',5); ?&gt;
    **This will output: &lt;meta http-equiv='refresh' content=5;url=http://10.0.0.5/project/admin&gt;
    **Note: This function redirects to the base_url() function plus the actuall destination within the application,
    **you cannot use it to redirect, to a different domain.
    */
    function set_redirection($destination = NULL,$time = 0)
    {
    if(!$destination == NULL){return "&lt;meta http-equiv='refresh' content=".$time.";url=".base_url().$destination."&gt;";}
    else { return "Invalid Destination Set"; }
    }
    
    /*Function set_custom()
    **No default values are within the library.
    **2 parameters can be defined for this function, the content of the status,
    **and the type in this case a custom div class defined on your css file.
    **Usage Example: &lt;?php echo $this->status->set_custom('Custom Message','someclass'); ?&gt;
    **This will output: <div class='someclass'>Custom Message</div>
    */
    function set_custom($content = NULL,$type = NULL)
    {
    if(!$type == NULL){return "<div class='".$type."'>".$content."</div>";}
    else { return "Invalid Type Set"; }
    }
}
/* End of file Status.php */
/* Location: ./system/application/library/Status.php */