View Single Post
Old 01-07-2009, 02:19 AM   #15 (permalink)
Scottymeuk
The Contributor
 
Join Date: Jan 2009
Posts: 40
Thanks: 10
Scottymeuk is on a distinguished road
Default

Ok thanks for all the help guys, I have decided to use Kalle's way of doing it as he showed me on msn that its a good way. The class is:

PHP Code:
class core
{
    protected static 
$instance
    protected static 
$objects = Array(); 

    private function 
__construct() 
    { 
    } 

    private function 
__clone() 
    { 
    } 

    public function 
__get($component
    { 
        
$component strtolower((string) $component); 
        if(
array_key_exists($componentself::$objects)) 
        { 
            return(
self::$objects[$component]); 
        } 
        return(
NULL); 
    } 

    public static function 
init() 
    { 
        if(!
is_object(self::$instance)) 
        { 
            
self::$instance = new self
        } 
        return(
self::$instance); 
    } 

    public static function 
load($component
    { 
        
$component strtolower((string) $component); 

        if(
array_key_exists($componentself::$objects)) 
        { 
            return(
true); 
        } 
        
$class $component
        if(!
class_exists($class)) 
        { 
            die(
$class ' - class not found!'); 
        } 

        
self::$objects[$component] = new $class

        return(
self::$objects[$component]); 
    } 

and i now use it like:

PHP Code:
class controller
{
    public 
$core;
    
    function 
controller()
    {
        
$this->core core::init();
    }   

PHP Code:
class theClass extends controller 
and on the index.php page i have:

PHP Code:
$core core::init();
core::load('app');
core::load('input');
core::load('session');
core::load('database');
core::load('user');
core::load('template');
core::load('form');
core::load('language'); 
and at the top of all files (not classes) i just use:

PHP Code:
$core core::init(); 
Thanks for all the help guys. Really appreciate it. No doubt I will be coming back with some more problems soon and then once i have all them sorted i can help others :). (Next problem is going to be something along the lines of view files and template system and controllers lol).

Thanks
Scottymeuk is offline  
Reply With Quote