tags:

views:

220

answers:

2

Hi there!

I'm using Zend framework, and most of the action controller that I have return XML response. In order to do this, I have to initialize context switching and provide URL suffix "?format=xml" to call each action.

Is there any way to make this default? So I don't have to add this suffix each URL?

Regards, Andree.

+1  A: 

EXTRA EXTRA.. READ ALL ABOUT IT!

http://framework.zend.com/manual/en/zend.controller.actionhelpers.html

Have a look at ContextSwitch and AjaxContext

(Edit) Suggest you use:

In some cases, you may want to force the context used; for instance, you may only want to allow the XML context if context switching is activated. You can do so by passing the context to initContext():

$contextSwitch->initContext('xml');

Phliplip
Yes, I do read about that before asking this question. But I can't find what I want there: to remove the need to add URL suffix "?format=xml" for each action to respond using XML.If you find the information that I need in the documentation, I would be glad if you could point out which one. Thanks! =)
Andree
Updated my answer
Phliplip
Thanks for the clarification! But still it does not work. I still have to use "?format=xml", otherwise the context is not changing.
Andree
Maybe you're not using it right ;) Try post some more code.
Phliplip
Now it's working. I have to do both initContext('xml') and addActionContext() to get it working.
Andree
Glad you got it working
Phliplip
A: 

What about explicitly setting the parameter format in the init() method of your controller?

$this->getRequest()->setParam('format', 'xml');

... there has to be a not so lazy way of doing this, though ...

nuqqsa
Yep it's working. Thanks!Still hoping if there's any less hacky solution though ;p
Andree