开发者

Where to put PHP files for AJAX in MVC architecture?

I'm creating site using MVC architecture and get stunned when I came to AJAX. I create simple feedback form with AJAX. When user submit it there is called PHP file that inserts given values into the database using 'database' class.

Where to put that PHP file (so it would be somehow hierarchic开发者_如何学C)?

I tried to put it in /models/ajax/file.php, but it seems to me stupid and, of course, 'database' class wasn't found.


It's no different than how you do any other page of your site. That this page's output goes to an AJAX request instead of directly to a web browser is irrelevant. Its logic goes in the controller, the database code goes in the model layer, its response goes in a view.


You should call controller from AJAX request. And response will probably use different (for example JSON) view

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜