Creating a custom JSON response object with Zend Action Helper ContextSwitch

前端 未结 2 507
暖寄归人
暖寄归人 2020-12-31 15:13

I normally append an encoded json object to the response body, however I now have a situation that warrants using the ContextSwitch action helper.

I have a Zend_Form

相关标签:
2条回答
  • 2020-12-31 15:24

    Personally, I don't use "View" to generate JSON content. In my init(), I have something like this:

    $ajaxContext = $this->_helper->getHelper('AjaxContext');
    $ajaxContext->setAutoJsonSerialization(false)
        ->addActionContext('index', array('html', 'json'))
        ->initContext();
    

    And In my indexAction():

    if ( true === $this->isAjaxJson() ) {
        $this->_helper->json(
            array(
                'response' => $myResponse,
                'message' => $myMesage
            )
        );
        return;
    }
    

    Hope this help.

    0 讨论(0)
  • 2020-12-31 15:25

    this may help : $this->_helper->json->sendJson($data); while,

    $data=array('data1'=>'val1','data2'=>'val2');

    0 讨论(0)
提交回复
热议问题