using objects

This is a discussion on using objects within the PHP General forums, part of the PHP Programming Forums category; Hello, I'm developing web aplication and I have some questions how to use object to get what I want. ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-18-2003
Uros
 
Posts: n/a
Default using objects

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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 02:36 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0