Welcome Guest, Not a member yet? Register   Sign In
Suggestion for best practice models
#5

[eluser]Hyra[/eluser]
That would ideally be the best. I agree.

But that would mean a lot of extra code in the controller.

For instance, showing the 8 latest additions (artworks) on the homepage would require something like:

Code:
$this->load->model('artwork');
$this->load->model('artist');
$this->load->model('comments');
$this->load->model('stats');

// get the latest additions
$LatestAdditions = $this->artwork->find('latest')->limit(4)->get();

// Find who posted them
$this->artist->get_artist_ids(&$LatestAdditions);

// Find the comments (to show how many per artwork)
$this->comments->get_comment_count(&$LatestAdditions);

// etc. etc.

This gets very lengthy, and since on 80% of the ArtInvolved.com pages artworks need to be shown, in different groups (Recommended Artworks, Related to current artwork, More artwork by artist), it will be a lot of repetitive code as well.

Using one "mother object" the code in the controller can be reduced to something like:

Code:
// Controller
$this->load->model('artwork');

$LatestAdditions = $this->artwork->find('latest')->limit(4)->get();

The model, in turn, then does all the other work that is described in the first bit of pseudo code. It will load everything up, find the belonging Artist-data, comments, etc. and then returns the whole lot as an object

Again, I do see the point of trying to get every model/object as capsulated as possible, but it seems to defeat the purpose if you need to rewrite a lot of code all the time.

Unless .. i DO use the intermediate "Browser Library" which translates the controller request into a lot of calls to different models.


Messages In This Thread
Suggestion for best practice models - by El Forum - 07-01-2009, 04:38 AM
Suggestion for best practice models - by El Forum - 07-01-2009, 04:13 PM
Suggestion for best practice models - by El Forum - 07-02-2009, 01:51 AM
Suggestion for best practice models - by El Forum - 07-02-2009, 02:09 AM
Suggestion for best practice models - by El Forum - 07-02-2009, 02:19 AM
Suggestion for best practice models - by El Forum - 07-02-2009, 02:47 AM
Suggestion for best practice models - by El Forum - 07-02-2009, 07:50 AM
Suggestion for best practice models - by El Forum - 07-02-2009, 08:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB