SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    Norwich UK
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Which way to get a list of objects?

    Hi,

    Say I've got a User object which allows me to manipulate a user's profile, now I have a user listing page where all the user appear so I can link through to the user I want to edit. What's the best way of coding this "listing" function?

    I could have a "Users" or "UserList" class which seems overkill, or maybe a separate procedural function, lastly what about a static function to the User object?

    This must be a really common choice, just curious as to what others do.

    James.
    Digital overload - a digital agency

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Possibly a method in your users class:

    PHP Code:
    getFromAllUsers$attributes$list_by $limit); 
    Which might act as a generic sql generator affording you a lot of flexibility, in fact your User might include a getSingle( $id, $attributes) ; where $attributes is an array.

    I wrote a simple single table generic CRUD class like this for my own "practice framework" recently. It checks off $attributes against a list of allowed attributes kept in an ini file. Seems to work quite nicely.

  3. #3
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't use the User object. A user is supposed to represent a single user, not a list of users.

    For list functions like this, I normally have a Site object (or System, or Store, or some other 'master' object), which i put all the site-wide funtions in. I would put a getUsers() funtion in there if I was doing it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •