|
|
Posted by NC on 06/25/06 23:43
LiveFreeAndRoam wrote:
>
> ------------------------------------------------
> class DataAccess extends MDB2 {
> // DataAccess properties and methods
> var $db;
> function __construct($dsn) {
> $this->db =& MDB2::factory($dsn);
> }
> }
>
> class Table {
> // table properties and methods
> var $dao;
> function __construct() {
> $this->dao = new DataAccess(); // <<< OK?
> }
> }
>
> class Product extends Table {
> // Product properties and methods
> }
> --------------------------------------------------
>
> One issue I have noticed is that when I attempt to recover
> the Product Object from the $_SESSION superglobal that
> the DataAccess object is unusable. MDB2 complains with:
>
> MDB2 Error: not found: could not find MDB2 instance
Try calling parent::__construct() explicitly within
DataAccess::__construct():
class DataAccess extends MDB2 {
// DataAccess properties and methods
var $db;
function __construct($dsn) {
parent::__construct(); // Are there required parameters?
//
-------------------------------------------------------------------
// Now DataAccess has all properties and methods
// of MDB2, including the factory() method, so you
// can call the factory() method directly:
$this->db =$this->factory($dsn);
}
}
> Is there a better way to design this?
Design has to achieve certain objectives. Since you didn't state your
objectives, no one can offer you an informed guess as to what other
design would be better to achieve those objectives...
Cheers,
NC
Navigation:
[Reply to this message]
|