• <bdo id='k7S89'></bdo><ul id='k7S89'></ul>
    1. <small id='k7S89'></small><noframes id='k7S89'>

      <i id='k7S89'><tr id='k7S89'><dt id='k7S89'><q id='k7S89'><span id='k7S89'><b id='k7S89'><form id='k7S89'><ins id='k7S89'></ins><ul id='k7S89'></ul><sub id='k7S89'></sub></form><legend id='k7S89'></legend><bdo id='k7S89'><pre id='k7S89'><center id='k7S89'></center></pre></bdo></b><th id='k7S89'></th></span></q></dt></tr></i><div id='k7S89'><tfoot id='k7S89'></tfoot><dl id='k7S89'><fieldset id='k7S89'></fieldset></dl></div>
    2. <tfoot id='k7S89'></tfoot>

      <legend id='k7S89'><style id='k7S89'><dir id='k7S89'><q id='k7S89'></q></dir></style></legend>

    3. 使用 Zend Action Helper ContextSwitch 创建自定义 JSON 响

      时间:2023-10-02

          <small id='RJu5J'></small><noframes id='RJu5J'>

              <tbody id='RJu5J'></tbody>

              <tfoot id='RJu5J'></tfoot>

              <legend id='RJu5J'><style id='RJu5J'><dir id='RJu5J'><q id='RJu5J'></q></dir></style></legend>
                <bdo id='RJu5J'></bdo><ul id='RJu5J'></ul>

                <i id='RJu5J'><tr id='RJu5J'><dt id='RJu5J'><q id='RJu5J'><span id='RJu5J'><b id='RJu5J'><form id='RJu5J'><ins id='RJu5J'></ins><ul id='RJu5J'></ul><sub id='RJu5J'></sub></form><legend id='RJu5J'></legend><bdo id='RJu5J'><pre id='RJu5J'><center id='RJu5J'></center></pre></bdo></b><th id='RJu5J'></th></span></q></dt></tr></i><div id='RJu5J'><tfoot id='RJu5J'></tfoot><dl id='RJu5J'><fieldset id='RJu5J'></fieldset></dl></div>
              • 本文介绍了使用 Zend Action Helper ContextSwitch 创建自定义 JSON 响应对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我通常会在响应正文中附加一个编码的 json 对象,但是现在我遇到了需要使用 ContextSwitch 操作助手的情况.

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

                我有一个 Zend_Form 需要三个不同的响应上下文:

                I have a Zend_Form that requires three different response contexts:

                1. html - 将表单呈现为普通的 html在布局内.
                2. html-partial - 呈现的 ajaxget"请求只是表单为 html.
                3. json - 返回的 ajaxpost"请求任何形式验证错误消息.
                1. html - Render the form as normal html within a layout.
                2. html-partial - An ajax "get" request that renders just the form as html.
                3. json - An ajax "post" request that returns any form valiation error messages.

                对于每个上下文,我有 3 个视图脚本.虽然这两个html上下文可以使用同一个视图脚本,但是我还没有弄清楚这是否可能.

                For each context I have 3 view scripts. Although the two html contexts could use the same view script, but I haven't figured out if this is possible.

                • form.phtml
                • form.html.phtml
                • form.json.phtml

                html 上下文视图可以正常工作,但是 json 视图没有被选中.覆盖默认 json post 回调行为或将自定义编码对象传递给响应正文的最佳方法是什么?

                The html context views work okay, but the json view is not being picked up. What is the best method to override the default json post callback behaviour or pass a custom encoded object to the response body?

                推荐答案

                就我个人而言,我不使用视图"来生成 JSON 内容.在我的 init() 中,我有这样的东西:

                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();
                

                在我的indexAction()中:

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

                希望对您有所帮助.

                这篇关于使用 Zend Action Helper ContextSwitch 创建自定义 JSON 响应对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Zend Framework 不活动后自动注销 下一篇:使用 PECL 操作系统在 PHP 5.1.6 上安装 PDO_MYSQL:Ubu

                相关文章

                最新文章

              • <i id='dvw7j'><tr id='dvw7j'><dt id='dvw7j'><q id='dvw7j'><span id='dvw7j'><b id='dvw7j'><form id='dvw7j'><ins id='dvw7j'></ins><ul id='dvw7j'></ul><sub id='dvw7j'></sub></form><legend id='dvw7j'></legend><bdo id='dvw7j'><pre id='dvw7j'><center id='dvw7j'></center></pre></bdo></b><th id='dvw7j'></th></span></q></dt></tr></i><div id='dvw7j'><tfoot id='dvw7j'></tfoot><dl id='dvw7j'><fieldset id='dvw7j'></fieldset></dl></div>
              • <tfoot id='dvw7j'></tfoot>
                • <bdo id='dvw7j'></bdo><ul id='dvw7j'></ul>

                <legend id='dvw7j'><style id='dvw7j'><dir id='dvw7j'><q id='dvw7j'></q></dir></style></legend>

                <small id='dvw7j'></small><noframes id='dvw7j'>