Welcome Guest, Not a member yet? Register   Sign In
A model per library
#1

[eluser]Hyra[/eluser]
Hey hey,

So. I've been restruggling with my community website. In specific: its structure.

This has been asked time and time again, but I'm getting quite frustrated since, even when reading the other topics, I can't figure out a sollution which works for _me_.

Please note: I'm not trying to start the old "model vs library". I'm merely hoping someone can shed some light on how I should go about with the following ..

-------

For the sake of simplicity, let's say the site I'm rebuilding at the moment is some sort of DeviantART. Users can create an account, upload artworks and get comments on them. Let's just say that's that's all there is to it.

Basically, the way i set it up now is to create libraries for the general tasks the site has to perform. So there is an artistlib, which retrieves data such as ArtistName, Reputation, Location with the help of a corresponding artistmodel.

There is a commentlib which retrieves comments for various parts (comments on a profile, comments on an artwork, etc.) .. again, with the help of a model .. commentsmodel.

The list goes on with artworklib, statslib, browselib, etc.

Thing is, commentslib (ab)uses artistlib heavily to "fill missing data" for the comments such as the name of the poster, the reputation, etc.

It all works, but it feels blodgy and fragile.

The reason i went with libraries was because some stuff will be altered, ordered or rewritten without database interaction, and some stuff will. Hence the model-variant of the library for the database calls.

At the moment I'm trying to figure out whether to:
- Either stick with this structure, which doesn't feel very right
- Just put all the (non database related) library methods in the model as well
- Expand the models so they cover more areas (i.e. comments will be part of the artwork model, as they belong to them)

I do realise this isn't as much a question as it is a "braindump", but I do hope someone can help me going again and put me in some sort of direction Smile


Appendix (for those who want some more info)

Just to illustrate, here's some more problem-cases.

The artist profile would show some boxes with information:

- Latest additions
- Comments from visitors
- Latest blog entry of the artist
- Some statistics (amount of artworks, comments received, etc.)

I was gonna solve this by doing something along the lines of:

Code:
function profile() {
    // Load the needed libs
    $this->load->library("commentslib");
    $this->load->library("browselib");
    $this->load->library("commentslib");
    $this->load->library("statslib");
    $this->load->library("bloglib");
    
    // Do some setting up
    $this->browselib->setArtist($this->artistid);
    
    $this->commentslib->setArtist($this->artistid);
    $this->commentslib->setCount(5);
    
    $this->bloglib->setArtist($this->artistid);
    
    $this->statslib->setArtist($this->artistid);
    
    // Fill the boxes
    $this->smarty_library->assign(array(
                "LatestAdditions" => $this->browselib->getLatestAdditions(),
                "Comments" => $this->commentslib->getComments(),
                "LatestBlogEntry" => $this->bloglib->getLatest(),
                "Statistics" => $this->statslib->getMinimalStats()
    ));
}

As you can see the setting up is repetitive. In this case it could be solved by passing the artist id as a config-parameter to the method.

Anyway, within the commentslib method, artistlib would be called, getting data from the artists who commented. It all just feels wrong.

Even though I like keeping things "modular" by using libraries, it does feel ackward as the libraries depend on each other and 90% of the time use models to complete the task, making them less modular than intended.

I'll stop rambling now .. hope anyone can help me get back on track Wink


Messages In This Thread
A model per library - by El Forum - 07-08-2008, 05:58 AM
A model per library - by El Forum - 07-08-2008, 11:41 PM
A model per library - by El Forum - 07-09-2008, 01:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB