dongpu9852 2009-02-19 19:39
浏览 61
已采纳

Zend Framework'AjaxContent'和ResponseSegmentation问题

I'm using jquery in Zend Framework, it's my first trial. I've already found out through another question, that I can change the response by changing the context like so:

$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('myaction', 'html');
$ajaxContext->initContext();

Now this has helped a lot but a new problem has shown:

My page consists of different responseSegments and when I responde to an Ajax request by changing the Context, my other ResponseSegments also 'think' they are sending Ajax but they're not. The front controller asks for a viewscript.ajax.phtml... which is wrong, it should be viewscript.phtml (exists).

  • 写回答

1条回答 默认 最新

  • doudeng9425 2009-02-19 19:52
    关注

    In the meantime I figured out how to solve this and because I think others will encounter the same problem in the future, I will answer my own question here:

    In my ActionSetup.php (or bootstrap.php if the action setup is not separated) I needed to make sure that actions are only pushed to the action stack, if the request was no XmlHttpRequest.

    The only thing that was missing was an if statement:

    if (!$request->isXmlHttpRequest())
    

    The whole thing looks like that:

    /**
     * Front Controller plugin to set up the action stack.
     *
     */
    class Project_Controller_Plugin_ActionSetup extends Zend_Controller_Plugin_Abstract
    {
        public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
        {
            if (!$request->isXmlHttpRequest())
            {
                $front = Zend_Controller_Front::getInstance();
                if (!$front->hasPlugin('Zend_Controller_Plugin_ActionStack'))
                {
                    $actionStack = new Zend_Controller_Plugin_ActionStack();
                    $front->registerPlugin($actionStack, 97);
                } else
                {
                    $actionStack = $front->getPlugin('Zend_Controller_Plugin_ActionStack');
                }
    
                $menuAction = clone ($request);
                $menuAction->setActionName('menu')
                ->setControllerName('index');
                $actionStack->pushStack($menuAction);
    
                $userlogAction = clone ($request);
                $userlogAction->setActionName('userlog')
                ->setControllerName('index');
                $actionStack->pushStack($userlogAction);
    
               //etc.
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?