www.webdeveloper.com
Results 1 to 2 of 2

Thread: Codeigniter custom library inheritance & functions

  1. #1
    Join Date
    Feb 2007
    Posts
    63

    Codeigniter custom library inheritance & functions

    Ok so i'll try and explain this as best as I can.

    I have a User class, and a Person class which extends / inherits from the User class, and possibly others which then further extend the Person class. I also have a Company class which extends the User class..
    So a User can be a Person or Company and they each have different fields associated with them depending on the type.

    The User class is a pretty generic class with basically login credentials in. The Person class contains your standard 'person' information like title, firstname etc etc.

    Each of these map to a seperate MySQL table in my database.

    In my Users class i've got a function called get_users_by_params which takes an array of parameters (fields) that I could potentially query.

    The same applies with the Person class; I have a get_persons_by_params. This is where my question is relevant. I need to get the associated user data in this same function, so i'm returning a fully populated Person object ie with the 'User credentials etc'. I'd like to keep all the User logic in the User class, and the Person logic in the Person class. So Ideally I'd want to call my get_users_by_params function from my Person class, and pass it my list of People to get the Userdata for.

    Can someone make some suggestions on what would be the best way of doing so ? I don't want to have to run an individual query for each 'Person' to get the User data because the list of people i'm returning could be massive. E.g. If i passed the User function 500 people, it would then need to run another query to get each of those peoples' user data thus resulting in a lot of queries - not good practice i'd imagine.

    Many thanks

    Al

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,146
    I might make a UserCollection class (and applicable child classes) that would consist at a minimum of:

    - A property that is an array of User objects
    - A method that populates that array based on the input selection parameters

    I would probably implement the Iterator interface, and possibly some __get()/__set() methods to access specific objects from that array.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles