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 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程