Skip to:
Content
Pages
Categories
Search
Top
Bottom

Using classes

  • Avatar of Grosbouff
    grosbouff
    Participant

    @grosbouff

    Hello, I don’t understand very well how to use classes.

    I think I have to use a class for each table of my component.

    Let’s say I want a table for all the component options (wp_bp_classifieds_options).

    How to construct a class for that table;

    How to script a function inside that class to retrieve a value (meta_value) using a key (meta_key)

    and how must I call that function in my script ?

    Thanks A LOT ! Hope i’ll make it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Avatar of John James Jacoby
    John James Jacoby
    Keymaster

    @johnjamesjacoby

    And so begins a young padiwan learner into the world of plugin creation. :)

    The best instruction I can give you, would be to stare at the existing core components, and other plugins that are out there currently. Stare at it long and hard. Eventually, you will see the light. Haha!

    For real though, if you’re not used to this type of event driven development, it can be really loopy and confusing at first. The best thing to do is watch it in action by looking at how other people have done what you’re trying to do, then take what works, delete what doesn’t, and fill in the blanks. There is no quick lesson anyone can give on how exactly to do this, as different types of plugins will require different depths of classification and development.

    Remember – you don’t have to use classes if you don’t want to. If you’re more comfortable using regular DB access functions then that’s fine.

    Each data access class is constructed to represent one table. Each column in the table maps to a class member variable. When then class is instantiated and turned into an object, that object should represent the data for one row of the table.

    When you call the save() method then class will determine if the row already exists and update the information in the table. If it does not exist, it will add a new row to the table.

    So here is an example of using a class like this:

    $house = new BP_House;
    $house->roof = 'tiled';
    $house->walls = 'wood';
    $house->door = 'PVC';
    $house->garden = 'grass';
    $house->save();

    So in this instance $house is a new object created from the class BP_House. When we call the $house->save() method, the data is saved to the database by the class.

    Not sure if that helps at all.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.