NYCPHP Meetup

NYPHP.org

[nycphp-talk] Accessing a method from one class in another

Daniel Convissor danielc at analysisandsolutions.com
Sat Jan 14 18:04:37 EST 2006


Hey Randal:

On Sat, Jan 14, 2006 at 12:48:41PM -0500, Randal Rust wrote:
> 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)

Easiest thing to do is in the class_content class, have a property named 
$db and set it in the constructor.  Or, have all your classes extend from 
the DB class.

class foo {
    public $db = null;

    public function __construct() {
        include PATH . '/include/class_db.inc';
        $this->db = new DB;
    }
}

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list