Main Stories
Slash Boxes

Slash Open Source Project

Slashcode Log In

Log In

[ Create a new account ]

Adding Elements to Users and Stories

posted by Krow on 07:48 AM June 18th, 2001   Printer-friendly   Email story
A while ago people asked about a tips and tricks topics for the site. So, we now have a topic, but we need content :)
What follows is the first in what I hope will be a set of stories on how to extend your slash site (and hopefully not all of these will be written by me).
BTW, thanks should go to Nathan Vonnahme for finding the new icon.
So with version 2.0 we found that we had a problem with users and stories. Namely each constantly needed to be extended everytime we added a new value. Frequently we had cases where either a story needed an image or users needed a new entry (say for instance you wanted to record the ICQ number of a user). To get around this param tables were added to each of these table sets.

Basically this means that for any user or story you can add arbitrary key values without extending the schema. So for instance if you called $slashdb->setUser(2, {icq => 324234}) and then called $slashdb->getUser(2, 'icq') then you would get back the value that was stored for the user (if you have a current $user hash, the value will also be found in it, so $user->{icq} would also return the user's icq number).

This also applies to stories. If you need to add new elements to stories you can call setStory()/getStory(). Since the frontpage happens to use a getStory() you will find that it is easy to add elements such as images to be displayed with your stories by adding some simple IF logic to your dispStory templates.

At the moment you will also need to modify along with its templates to make it easier to add elements to stories (someday I am hoping that the story editor in allows new elements to be added on the fly).
I am sure that once you play with this for a while you can find uses for it in your own sites.

This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login
Loading... please wait.
  • Thanks for that explanation! I couldn't puzzle out the param tables stuff from the Slash::DB::MySQL code.

    Where should I put setStory/setUser though? I could put them in templates, but it needs to be done after a form is submitted, usually. So... put them in the template that's displayed after the user/story is saved? That seems a bit funky but I guess it would work.

    So, would doing something like this in a template be right?

    USE Slash;
    Slash.db.setUser(user.uid, {icq => form.icq});
    global = useless
  • Depends on what you are up to. If you are writing your own plugin (or theme) just put them in the code. If not, you could do it in a template.

    You can't grep a dead tree.