Re: [PHP] Access parent property from child

2007-08-09 Thread Suprie
ouch... hey it's work rite now... thanks a lot for your help Edward
and Stut, i really apprieciate it...

br///

On 8/9/07, Stut <[EMAIL PROTECTED]> wrote:
> Suprie wrote:
> > function getDB()
> > {
> > return $this->$db;
> > }
>
> There should not be a $ before db. It should be $this->db. That's why
> PHP is telling you the property is empty... because it is.
>
> -Stut
>
> --
> http://stut.net/
>


-- 
Jangan tanyakan apa yang Indonesia telah berikan pada mu
tapi bertanyalah apa yang telah engkau berikan kepada Indonesia

-BEGIN GEEK CODE BLOCK-
Version: 3.1
GU/IT  d- s: a-- C++ UL P L++ E W++ N* o-- K-
w PS  Y-- PGP- t++ 5 X R++ tv  b+ DI D+ G e+ h* r- z?
 --END GEEK CODE BLOCK--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Access parent property from child

2007-08-09 Thread Edward Kay


> -Original Message-
> From: Suprie [mailto:[EMAIL PROTECTED]
> Sent: 09 August 2007 11:13
> To: php-general@lists.php.net
> Subject: [PHP] Access parent property from child
>
>
> dear all ...
>
> i have question, i've tried look at google but still can't figured out
> how to do it...
> i want access parent property from child object the code was like
>
> 
> class DAO
> {
> private $db;
> private $id;
>
> protected function getId()
> {
> return $this->id;
> }
> protected function setId($id)
> {
> $this->id   = $id;
> }
>
> function getDB()
> {
> return $this->$db;
> }
> function setDB($db)
> {
> $this->db   = $db;
> }
>
> public function load($id)
> {
> $query  = "SELECT * FROM ".
> constant(get_class($this)."::tableName").
> " WHERE ".
> constant(get_class($this)."::pkFields").
> "='".$id."'";
> $rs = $this->db->Execute($query);
> $cObj   = $rs->FetchObject(true);
>
> return $cObj;
> }
>
> public function save($rowData)
> {
> $this->db->debug = true;
> $query  ="Select * FROM
> ".constant(get_class($this)."::tableName")."\n";
> $res=$this->db->Execute($query);
> $insertSQL  = $this->db->GetInsertSQL($res,$rowData);
> $res=$this->db->Execute($insertSQL);
> if($res)
> return true;
>
> return false;
> }
>
> public function update($row, $id)
> {
> $query  =   "SELECT * FROM
> ".constant(get_class($this)."::tableName")."\n"
> .   "WHERE
> ".constant(get_class($this)."::pkFields")."='".$id."'";
> $res= $this->db->Execute($query);
> $updateSQL  = $this->db->GetUpdateSQL($res,$row);
> $db->Execute($updateSQL);
> }
>
> public function getAll($criteria='', $order='')
> {
> if(empty($order))
> $order  = constant(get_class($this)."::pkFields");
>
> $query  = "SELECT * FROM
> ".constant(get_class($this)."::tableName")."\n"
> . $criteria
> . "ORDER BY ".$order;
> $row=   $this->db->Execute($query);
> if(!$row)
> {
> $this->error= $this->db->ErrorMsg();
> return  false;
> }
> return $row->getArray();
> }
>
> }
>
> and i have this child
> 
> include 'BaseDAO.class.php';
> class TaskCLDAO extends DAO
> {
> const tableName = 'task';
> const pkFields  = 'task_id';
>
> function findWithRelation($id)
> {
>   $query = "select * from task LEFT JOIN log ON
> task.id=log.task_id";
>   $db  =  parent::getDB();
>   $res =  $db->Execute($query);
>   return $res->getArray();
> }
> }
>
>
> ?>
>
> and this is the class that called it
>
> 
> $obj   = new TaskCLDAO();
> $obj->setDB($db); //  i have another file called config that
> initialized the db;
> $res   = $obj->findWithRelation(1);
>
> ?>
>
> but the php's said
>
> Fatal error: Cannot access empty property...
>
> what does it mean ?? is there another way to access "$db" that
> parent have ?
>
> TIA


In function getDb()

  return $this->$db;

should be:

  return $this->db;

Also, although not strictly required, I suggest you add the public keyword
to your methods that don't specifiy their visibility.

Edward

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Access parent property from child

2007-08-09 Thread Stut

Suprie wrote:

function getDB()
{
return $this->$db;
}


There should not be a $ before db. It should be $this->db. That's why 
PHP is telling you the property is empty... because it is.


-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Access parent property from child

2007-08-09 Thread Suprie
dear all ...

i have question, i've tried look at google but still can't figured out
how to do it...
i want access parent property from child object the code was like

id;
}
protected function setId($id)
{
$this->id   = $id;
}

function getDB()
{
return $this->$db;
}
function setDB($db)
{
$this->db   = $db;
}

public function load($id)
{
$query  = "SELECT * FROM ".
constant(get_class($this)."::tableName").
" WHERE ".
constant(get_class($this)."::pkFields").
"='".$id."'";
$rs = $this->db->Execute($query);
$cObj   = $rs->FetchObject(true);

return $cObj;
}

public function save($rowData)
{
$this->db->debug = true;
$query  ="Select * FROM
".constant(get_class($this)."::tableName")."\n";
$res=$this->db->Execute($query);
$insertSQL  = $this->db->GetInsertSQL($res,$rowData);
$res=$this->db->Execute($insertSQL);
if($res)
return true;

return false;
}

public function update($row, $id)
{
$query  =   "SELECT * FROM
".constant(get_class($this)."::tableName")."\n"
.   "WHERE
".constant(get_class($this)."::pkFields")."='".$id."'";
$res= $this->db->Execute($query);
$updateSQL  = $this->db->GetUpdateSQL($res,$row);
$db->Execute($updateSQL);
}

public function getAll($criteria='', $order='')
{
if(empty($order))
$order  = constant(get_class($this)."::pkFields");

$query  = "SELECT * FROM
".constant(get_class($this)."::tableName")."\n"
. $criteria
. "ORDER BY ".$order;
$row=   $this->db->Execute($query);
if(!$row)
{
$this->error= $this->db->ErrorMsg();
return  false;
}
return $row->getArray();
}

}

and i have this child
Execute($query);
  return $res->getArray();
}
}


?>

and this is the class that called it

setDB($db); //  i have another file called config that initialized the db;
$res   = $obj->findWithRelation(1);

?>

but the php's said

Fatal error: Cannot access empty property...

what does it mean ?? is there another way to access "$db" that parent have ?

TIA
-- 
Jangan tanyakan apa yang Indonesia telah berikan pada mu
tapi bertanyalah apa yang telah engkau berikan kepada Indonesia

-BEGIN GEEK CODE BLOCK-
Version: 3.1
GU/IT  d- s: a-- C++ UL P L++ E W++ N* o-- K-
w PS  Y-- PGP- t++ 5 X R++ tv  b+ DI D+ G e+ h* r- z?
 --END GEEK CODE BLOCK--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php