On Monday, April 09, 2007 3:51 PM Jochem Maas
<mailto:[EMAIL PROTECTED]> said:

Thanks for the response Jochem.

> Chris W. Parker wrote:

[snip]

> you probably only want one DB call to
> populate the User object with all the relevant
> user data at the point where the object is created.

[snip]

Ok. I see what you're saying. If I populate all that data during the
constructor why would I ever call the function again right?

[snip]

>> As I started to write this and use it I get the feeling that there
>> should also be an Event class that is extended by the User class.
>> Reason 
> 
> if you use an Event class then it should just represent an Event (and
> a User object would [probably] contain an array of Event objects).
> AFAICT there is no good reason to have Event extend User.

I see.

>> being that each User object is a reference to the currently logged in
>> user, not anyone else.
> 
> the User class is merely a representation of *a* user - you can
> use an instance for the currently logged in user, but that doesn't
> stop you from using the same class to model the collection of users
> that fall under a given manager.

I see.

> // you might need to f around with returning references here,
> // (I can never quite get that right without a bit of trial and error
> in php4) function getEmployees()
> {
>       // consider caching the result?
>       $emps = array();
>       if ($this->is_manager) {
> 
>               // get user data from db
>               $sql = "SELECT * FROM users WHERE
manager_id={$this->id}";
> 
>               // error checking?
>               $db =& DB::singleton();
>               $db->execute($sql);
>               while ($data = $db->getRow())
>                       $emps[] =& new User($data);
>       }
> 
>       return $emps;
> }

How do I reference a User object within the $emps array?

Is it like $emps[0]->accrual ?




Thanks,
Chris.

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

Reply via email to