开发者

MVC (codeigniter) design question

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 "s开发者_高级运维witch case" in a really complicated way.

thank you.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜