Welcome Guest, Not a member yet? Register   Sign In
strict mvc or loose it up a litte
#1

[eluser]searain[/eluser]
I have an page to display event detail.

Event Title
Event Time
Event Description

No problem.

I have event_model.php to do the database query and return results to the event_view.php page to display.

But now,

The event could have sub events (identified by parent_id). So event detail could be

Event Title
Event Time
Event Description
Sub Event Title
Sub Event Time
Sub Event Description

Sub Event Title
Sub Event Time
Sub Event Description

Sub Event Title
Sub Event Time
Sub Event Description

So an easy solution is in the view page like above, query the sub event id one by one, and display them after query the data (in view page).

A MVC solution is still in event model page, query all the sub events. Return the sub events results with the parent event detail to the view page. This is doable. But in theory, if we have more layers of sub events such as

Event Title
Event Time
Event Description
Sub Event Title
Sub Event Time
Sub Event Description
SubSub Event Title
SubSub Event Time
SubSub Event Description
SubSubSub Event Title
SubSubSub Event Time
SubSubSub Event Description

Then doing all these layers sub..sub events query and return all results to the root event view page will be complicated.

But if we just query the sub events in the view page, in that layer, pick up the sub event id, do the query, return results and display, and then in the next layer, pick up the sub event id and do the query ... (all these subquery happens in view page) that will be easier.

So then should I stick with the rule that all database query in model, view only for view. or sometimes do query data in view page?

Is there a better solution that I can still do strict MVC but keep it simple?

Thanks!
#2

[eluser]Sarfaraz Momin[/eluser]
Well I can try to explain a solution that I used for a similar scenario where I had categories and unlimited levels of subcategories. I did put a lot of time trying to do things in MVC and what I found was that its pretty much doable with at the cost of lot of queries which in my case was not acceptable as it was hitting the performance of the application. So I have to add a new field to my category table just to let me know what level of category this one is.
So physically only categories exists but if a category is anywhere above level 0 means it is a subcategory. Ebay came to my rescue with this solution as I had worked on an ebay app earlier and know that while pulling categories from ebay it returns the level of category as well to let us know which level it stands.
I think this should somewhat explain it. Lets see if there are any other issues with it. Maybe a simple db schema will surely help. I will try to get it done if need be.

-Sarfaraz.
#3

[eluser]searain[/eluser]
How about a binary tree solution?

I need to think about it more or dig out more info about the binary tree.




Theme © iAndrew 2016 - Forum software by © MyBB