English 中文(简体)
MVC (编码用户)设计问题
原标题:MVC (codeigniter) design question

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

所有销售时间间隔(用户提交时间间隔),

选定城市在间隔时间的所有销售(与以上数字相同,但该市除外选择下降),

销售20个商店的顶点(其他报告,无表格提交,有不同的表格)

等等

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 必须说明我的背景是程序拟定,而且混淆不清。 一切似乎都像以真正复杂的方式撰写基本的“巫术案”。

谢谢。

问题回答

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.





相关问题
PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

What s the proper MVC way to do this....?

Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I m actually using Kohana). I m new to MVC and don t want to get this wrong... so I m wondering if i have ...

Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

CodeIgniter adding semicolons

How do I stop CodeIgniter adding semicolons ; to data sent via POST that contains ampersand &? For example it is converting "a=1&b=2&c=3" into "a=1&b;=2&c;=3". From looking on the forums ...

Best way to make Admin pages in CodeIgniter?

I m working on an app in CodeIgniter, and I want to have admin pages for several of the objects in the application, and I m wondering what would be the better way to put these into an MVC structure. ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签