views:

140

answers:

2

I'm developing a zend framework app that's just going to act as a web service. I have no need to ever output HTML at any point in the application and don't even want the overhead of creating empty view files.

I want my app to output XML by default, JSON if requested (via the format parameter would be fine).

Is there any way to do this without explicitly defining the context switching rules in the init() part of every controller?

A: 

you could try doing the context switch using a Zend_Controller_Front plugin on preDispatch.

Valentin Bora
+2  A: 

If you're going to be providing JSON, SOAP or XML-RPC, you're probably better off using Zend_Json_Server + Zend_Soap_Server instead of Zend_Controller_Action. Both the JSON and SOAP server classes can consume the same server class. No need for the overhead of routing, etc.

Matthew Weier O'Phinney's (Zend FW lead), site has a great post detailing the proper way of doing this: Exposing Service APIs via Zend Framework

Andy Fowler