Re: DB_DataObject custom fetch function
| From: | Thomas Mammitzsch | Date: | Wed, 18 Aug 2004 20:18:35 +0000 |
| Subject: | Re: DB_DataObject custom fetch function | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-14169@lists.php.net to get a copy of this message | ||
Justin Patrin wrote:
I did everything like mentioned above, but i get the error "Fatal Error: Cannot redeclare clas mydataobject in inc/MyDataObject.php on line 4" i created a file MyDataObject.php: ------------snip----------- require_once ('DB/DataObject.php'); class MyDataObject extends DB_DataObject {function fetch_all($object) {Yes, this is the right answer. Put it all in your own class which extends DB_DataObject, then have your DOs extends that one. You can even set it in yout ini file and tell the generator to re-write the extends section (with another ini setting). thanks for your response!...} whats the best place to define this function? I don't want to put it in every DataObject Class(the table specific ones). Maybe defining an own class extending the base DataObject Class and tell every Dataobject class to extend my class instead of the base class? how are you handling this?
function fetch_all($object)
{
...
}
}
----------------------------
my index.php now looks like this:
----------snip---------------
require_once("inc/MyDataObject.php");
$navigation = MyDataObject::factory('Navigation');
$navigation->orderBy('id ASC');
$navigation->find();
$menu=$navigation->fetchall($navigation);
------------------------------
the DataObjects/Navigation.php looks like this:
---------snip-----------------------
require_once 'inc/MyDataObject.php';
class DataObjects_Navigation extends MyDataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
var $__table = 'navigation'; // table name var $id; // int(10) not_null primary_key unsigned var $name; // string(255) not_null/* ZE2 compatibility trick*/ function __clone() { return $this;} /* Static get */ function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Navigation',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE } ------------------------------------- what am i doing wrong? regards, Thomas