开发者

Module only to process Ajax requests

I am creating an application that will make heavy use of Ajax and performance is required. I've searched the best ways to handle Ajax requests using the Zend开发者_如何学C Framework, and saw that the most commonly used ways are the Context-switch and/or an Action per Controler to handle Ajax requests. If I were to use the first way I would have to keep a script in the view for each type of format that I could return (JSON, XML, etc.), and I think it's unnecessary, and the second way, I would get an action full of if/elses.

I do not see anyone suggesting the creation of a module only for Ajax, this would be a bad practice? In my opinion this would make things easier, and the whole code for Ajax would be in one place, I would like to know what you think about it before making a decision, and of course, constructive criticism is welcome.


If you have a controller which only needs to handle AJAX, then you can just use the views as usual. The context switch is meant for cases where an action needs to serve multiple types of contents (JSON, XML, HTML etc.).

If you know that the whole controller will just output JSON, for example, you can create a single view (or no view at all) and call this particular view from all actions in the controller.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜