0

私はこのコードベースに取り組んできましたが、サイトwww.site.com/version/にアクセスするとhtmlで応答します。

ただし、www.site.com / version?format = xmlにアクセスすると、出力がxmlで表示されます。

フォーマット要求に関係なく、ZendコードをXMLでのみ出力するように変更するにはどうすればよいですか?ええ、私はZendコーディングに不慣れです...)

私のコードはまさにクリスが持っているものです(http://www.chrisdanielson.com/2009/09/02/creating-a-php-rest-api-using-the-zend-framework/):

class VersionController extends Zend_Rest_Controller
{  
public function init()
{
    $bootstrap = $this->getInvokeArg('bootstrap');

    $options = $bootstrap->getOption('resources');

    $contextSwitch = $this->_helper->getHelper('contextSwitch');
    $contextSwitch->addActionContext('index', array('xml','json'))->initContext();

    //$this->_helper->viewRenderer->setNeverRender();   
    $this->view->success = "true";
    $this->view->version = "1.0";
}
 ...
 ...
4

1 に答える 1

1

次のコードによってのみ、コンテキストにXMLを使用させることができます。

$ this-> _ helper-> contextSwitch()-> initContext('xml');

リンクを参照してください:

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

于 2011-03-25T00:00:10.793 に答える