Re: DB_DataObject custom fetch function
| From: | Justin Patrin | Date: | Wed, 18 Aug 2004 20:30:02 +0000 |
| Subject: | Re: DB_DataObject custom fetch function | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-14170@lists.php.net to get a copy of this message | ||
On Wed, 18 Aug 2004 22:18:35 +0200, Thomas Mammitzsch <smartt@gmx.de> wrote:
> Justin Patrin wrote:
>
> >>function fetch_all($object)
> >>{
> >> ...
> >>}
> >>
> >>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?
> >>
> >>
> >
> >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!
> 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)
> {
> ...
> }
> }
> ----------------------------
>
> 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';
>
Are you sure this is a require_once? If it is, are you sure that it's
the same *case* in all of your require statements? It's somehow being
defined twice. Try putting an echo in the top of that file and see how
many times it prints out.
> 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?
>
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--