views:

35

answers:

1

users want to see some reports from stored data in the db for example:

all sales in a time interval (user submits a just a time interval),

all the sales in the selected city in a time interval (same with above but this time extra city select dropdown),

top selling 20 shops (another report , no form submission and different db tables involved ),

etc

My problem is how can i accomplish these task without writing a separate model, controller and view for each report or each report has a method in a single controller and model and two views (one for form submission 1 for results).

i must tell my background is procedural programming and i am confused. everything seems like writing basic "switch case" in a really complicated way.

thank you.

A: 

This depends on how you structure your db. Although having lots of models might seem like overkill I would suggest that if you approach it in the right way you will find it makes your life easier. For example you could have a model that deals with sales. Within that model there could be a function to retrieve all sales by date or time. This function could have an optional parameter to allow you to filter by city. You might then have another function in the same model to retrieve the top 20. From the controller you would have one function. This would be one big if statement based on whether or not the user had submitted the form. If not then display the form view (it is best to have separate views for specific things or at least fragments of views). If data has been submitted then simply test the data to find out which report is required, query the relevant method in your model and send the results to another results view. This way, one controller, one model, 2 views ( or more if you're using a template kind of thing). I deliberately haven't written the code for you, but I hope this points you in the right direction. Please comment if ive misunderstood the question or you need clarification.

musoNic80
i appreciate your answer . i get what you are saying and it helps me. but i have over 100 of these reports and they are using over 20 db tables which related or unrelated to each other. so i am dreaming about a way , when im adding a new report to the system, i will supply form fields and a query to some homemade mechanism and it will bring back the form for user and show the report. seems like MCV doesnt enable me to this easier than any other way. i was reading about libraries,helpers,plugins etc.. i guess i am trying to be overcreative beacuse of laziness. thank you again.
bezelye