Welcome Guest, Not a member yet? Register   Sign In
display common data accross all pages
#17

[eluser]InsiteFX[/eluser]
Here is something that I have been playing with, still working on it but it does work!
You can also store array's if you serialize and unserialize them.
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Class        Registry
*
* @package        CodeIgniter
* @subpackage    Libraries
* @category    Libraries
* @author        Raymond King aka:(InsiteFX).
* @copyright    Copyright (c) 2005 - 2011, Advanced Computer Systems, LLC.
* @license        http://www.learnellislab.com/codeigniter/user-guide/license.html
* @link        http://www.learnellislab.com/codeigniter/user-guide/libraries/name.html
* @since        Version 1.0.0
*/

// Autoload this library in application/config/autoload.php

class Registry {

    /**
     * Class Variables - protected, private, public and static variables.
     * --------------------------------------------------------------------
     */
    private static $registry = array();


    // --------------------------------------------------------------------

    /**
     * __construct()
     *
     * Class    Constuctor PHP 5+
     *
     * @access    public
     * @param    array
     * @return    void
     */
    public function __construct($config = array())
    {
        // NOTE: if you use a config file it must be named the same as this Class!
        // application/config/registry.php
        foreach ($config as $key => $value)
        {
            if ( ! self::exists($key))
            {
                self::$registry[$key] = $value;
            }
        }
    }

    // --------------------------------------------------------------------

    /**
     * add() - Example: $this->registry->add($key, $value);
     *
     * Adds an item to the registry array
     *
     * @access    public
     * @param    string    - item's unique key
     * @param    mixed    - value
     * @return    boolean
     */
    public function add($key, $value)
    {
        if ( ! self::exists($key))
        {
            self::$registry[$key] = $value;
            return TRUE;
        }
        else
        {
            return FALSE;
        }
    }

    // --------------------------------------------------------------------

    /**
     * exists() - Example: $result = $this->registry->exists($key);
     *
     * Returns TRUE if item is registered in the registry array
     *
     * @access    public
     * @param    string    - key name
     * @return    boolean
     */
    public function exists($key)
    {
        if (is_string($key))
        {
            return array_key_exists($key, self::$registry);
        }

        return FALSE;
    }

    // --------------------------------------------------------------------

    /**
     * get() - Example: $this->registry->get($key);
     *
     * Returns the registered key value
     *
     * @access    public
     * @param    string    - key name
     * @return    mixed    - (FALSE if key name is not in registry array)
     */
    public function get($key)
    {
        if (self::exists($key))
        {
            return self::$registry[$key];
        }

        return FALSE;
    }

    // --------------------------------------------------------------------

    /**
     * delete() - Example: $result = $this->registry->delete($key);
     *
     * delete's a registry entry
     *
     * @access    public
     * @param    string    - key name
     * @return    boolean
     */
    public function delete($key)
    {
        if (self::exists($key))
        {
            unset(self::$registry[$key]);
        }

        return TRUE;
    }

    // --------------------------------------------------------------------

    /**
     * clear() - Example: $this->registry->clear();
     *
     * Clears the entire registry array
     *
     * @access    public
     * @return    boolean
     */
    public function clear()
    {
        self::$registry = array();
    }

    // --------------------------------------------------------------------

    /**
     * debug() - Example: echo var_dump($this->registry->debug());
     *
     * Return's the entire registry array for debugging
     * @access    public
     * @return    array
     */
    public function debug()
    {
        return self::$registry;
    }

}


// ------------------------------------------------------------------------
/* End of file Registry.php */
/* Location: ./application/libraries/Registry.php */

InsiteFX


Messages In This Thread
display common data accross all pages - by El Forum - 05-30-2011, 10:03 AM
display common data accross all pages - by El Forum - 05-30-2011, 10:41 AM
display common data accross all pages - by El Forum - 05-30-2011, 11:30 AM
display common data accross all pages - by El Forum - 05-30-2011, 11:36 AM
display common data accross all pages - by El Forum - 05-30-2011, 11:40 AM
display common data accross all pages - by El Forum - 05-30-2011, 11:42 AM
display common data accross all pages - by El Forum - 05-30-2011, 12:24 PM
display common data accross all pages - by El Forum - 05-30-2011, 12:32 PM
display common data accross all pages - by El Forum - 05-30-2011, 08:02 PM
display common data accross all pages - by El Forum - 05-30-2011, 10:43 PM
display common data accross all pages - by El Forum - 05-30-2011, 11:49 PM
display common data accross all pages - by El Forum - 05-31-2011, 01:23 AM
display common data accross all pages - by El Forum - 05-31-2011, 01:33 AM
display common data accross all pages - by El Forum - 05-31-2011, 05:02 AM
display common data accross all pages - by El Forum - 06-02-2011, 08:15 AM
display common data accross all pages - by El Forum - 06-02-2011, 09:12 AM
display common data accross all pages - by El Forum - 06-02-2011, 09:15 AM
display common data accross all pages - by El Forum - 05-23-2012, 08:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB