[nycphp-talk] Accessing a method from one class in another
Randal Rust
randalrust at gmail.com
Sat Jan 14 12:48:41 EST 2006
Coming from a procedural background, I've been able to move to the OOP
way of doing things, but I am far from really mastering it, and making
things as reusable as I probably can. One thing that always bugs me is
how I access the DB object in all of the other classes.
I always include and instantiate the DB this way:
include 'class_db.php';
$db = new DB;
$db = $db->conn;//the db object is generated with the help of ADODB
Then, in my other classes, like class_content(), I pass the $db to
each method, like this:
function addContent($db, $type)
function viewContent($db, $rec)
function updateContent($db, $rec)
This works OK when I'm dealing with the DB object, but there are a
couple of other classes, like class_image that I need to access in
other classes as well. It doesn't make sense to have this...
function addContent($db, $image, $type)
...so that I can have access to all of the methods for class_image
inside of class_content.
What is it that I'm not grasping?
--
Randal Rust
R.Squared Communications
www.r2communications.com
More information about the talk
mailing list