Set the default context in the Zend environment for XML

I use the Zend framework, and most of the action controller I return an XML response. To do this, I need to initialize the context switch and provide the URL suffix "? Format = xml" to invoke each action.

Is there a way to do this by default? So I don’t need to add this suffix to every URL?

Regards, Andrew.

+3
source share
4 answers

EXTRA EXTRA .. READ EVERYTHING ABOUT IT!

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

Take a look at ContextSwitch and AjaxContext

(Change) Suggest using:

; , XML, . , initContext():

$contextSwitch- > initContext ( 'XML');

+7

format init() ?

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

... , ...

+3

- , , "format":

$ajaxContext = $this->_helper->getHelper('AjaxContext');
$currentContext = $ajaxContext->getCurrentContext();
if (empty($currentContext)) {
    $ajaxContext->initContext('xml');
}

init() , . .

, , "format":

$ajaxContext->setContextParam('type');

Then you can invoke your action with "/ controller / action / type / xml".

0
source

If you do not want to set a parameter in each init controller, you can also set the parameter as a global route parameter. In your bootstrap, pull out the router instance and call

$router->setGlobalParam('format', 'xml');

Or you can set the default values ​​in the routes you define or, possibly, when using the default router anywhere in your URL after your name params / format / xml.

0
source

Source: https://habr.com/ru/post/1748492/


All Articles