|
|
Posted by LiveFreeAndRoam on 06/26/06 05:53
"NC" <nc@iname.com> wrote in message
news:1151278996.694450.283930@y41g2000cwy.googlegroups.com...
> 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
>
Thankyou NC.
In terms of objectives I would prefer to not have to do the following to
recover my DataAccess object to a state where it can be used:
$sessprod = unserialize($_SESSION['product']);
$product = new Product();
$product->setProperties($sessprod->getPropertiesExcludingDao());
$product->query($query);
I would prefer to simply do this:
$product = unserialize($_SESSION['product']);
$product->query($query);
Though, this isn't working for me as previously stated. I wondered whether
designing my class hierachies differently would allow me to achieve this
end.
Best Regards,
LFaR.
[Back to original message]
|