Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 23rd, 2005, 12:17 AM
Registered User
 
Join Date: Jan 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to sbalmos Send a message via AIM to sbalmos Send a message via MSN to sbalmos Send a message via Yahoo to sbalmos
Default Combining Collection & GenericObjectCollection?

Hi all,

In Professional PHP5, Chapters 5 & 9, there are discussions on how to implement collections of a base object. For the most part, these seem redundant to me, and the GenericObjectCollection class in Chapter 9 is the same as the Collection class, except it's DB-aware. I'm trying to think through a way to efficiently combining their functionality. Possible idea is below. DBObject is my renamed GenericObject, and pointless code is removed.

class Group extends DBObject
{
  private $_users;
  ...
  public function __construct()
  {
    ...
    $this->_users = new Collection();
    $this->_users->setLoadCallback('_loadUsers', $this);
  }
  ...

  public function _loadUsers(Collection $col)
  {
    // this is where, I guess, I would put some condensed implementation of GenericObjectCollection's loading logic?
  }
}

As you can see, I'm guessing that Collection's lazy-instantiation callback, _loadUsers, is where I would do some DB ops, like is described in GenericObjectCollection, to get all matching User objects from the User table in one query (using "... WHERE id IN (list-of-userids)"). But I guess I'm getting hung up on just how much screwing I can do with this. Maybe my head's just fuzzy from trying to code on a Saturday night.

Ideas on this? Thanks!

--Scott







Similar Threads
Thread Thread Starter Forum Replies Last Post
GenericObjectCollection nemesa BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 0 August 5th, 2006 02:51 PM
Javascript && keeps turnig into && ayrton Pro VB.NET 2002/2003 3 June 27th, 2005 03:34 PM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 05:41 PM
Combining tables spraveens Access 2 December 29th, 2003 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.