using objects

From: Date: Mon, 18 Aug 2003 13:41:02 +0000
Subject: using objects
Groups: php.general 
Request: Send a blank email to php-general+get-159916@lists.php.net to get a copy of this message
Hello, I'm developing web aplication and I have some questions how to use object to get what I want. I have init.php file wher I prepare everything (DB,Auth....) so I have several objects created. Then I have index.php which gets all requests and load requested modules. This modules have to use DB, Auth, Smarty ...... init.php < $db = new DB..... $auth = new Auth.... $tpl = new Smarty... ------------------------ index.php < $mod = loadModule('mod1'); $mod->getData()..... function loadModule($mod) { require $mod.'.php'; $m =& new $mod; return $m } ------------------------ mod1.php < Class mod1 { // some property function getData() { // here I want to use $db or $auth // right now I have only solution // to use global $db } } I hope this code explains what my needs. What is the best way. Or am I doing all wrong. Maybe some other ideas. What about global. I don't like to use $GLOBALS, because I want to use those object like in pear documentation, so without some strange coding, because this modules will be developed from public. I also tried to pass those objects with reference into Class when it was generated. But then I have to use $this->db etc. I search for this on the web but I couldn't find any good answers or projects. -- Best regards, Uros

« previous php.general (#159916) next »