Zend framework2 ZF2-it中的注册/登录覆盖';s自己的动作,JS打开并可能进行深层链接

Zend framework2 ZF2-it中的注册/登录覆盖';s自己的动作,JS打开并可能进行深层链接,zend-framework2,Zend Framework2,我的站点上有覆盖图和隐藏面板,它使用AJAX从另一个控制器/动作中提取内容。单击一个链接,该链接通过setTerminal(true)来pushState URL和AJAX获取内容这样就没有布局了。这些overlay/HiddenParel是登录/注册面板,并且在您请求页面时希望它们已经是HTML格式的,而不使用ajax(刷新),这样它们就可以被深度链接到 目前,我在寄存器控制器/操作中有类似的内容: public function registerAction () { $reques

我的站点上有覆盖图和隐藏面板,它使用AJAX从另一个控制器/动作中提取内容。单击一个链接,该链接通过
setTerminal(true)来pushState URL和AJAX获取内容这样就没有布局了。这些overlay/HiddenParel是登录/注册面板,并且在您请求页面时希望它们已经是HTML格式的,而不使用ajax(刷新),这样它们就可以被深度链接到

目前,我在寄存器控制器/操作中有类似的内容:

public function registerAction () {
    $request = $this->getRequest();

    // Possible $form = new RegisterForm(); with validation and error population etc

    // If we're not requesting via AJAX, forward dispatch to index
    if (!$request->isXmlHttpRequest()) {
        return $this->forward()->dispatch('index', array(
            'action' => 'index',
            'overlay' => 1
        ));
    }

    $view = new ViewModel();
    $view->setTerminal(true);
    return $view;

}
如果没有XmlHttpRequest,则它将通过以下检查转发到index/index:

public function indexAction () {
    $routeRequest = $this->getEvent()->getRouteMatch();

    $view = new ViewModel([]);

    // Check if user went to somewhere like register page
    $overlay = $routeRequest->getParam('overlay', null);
    if (null !== $overlay) {
        $view->overlay = true;
    }

    return $view;
}
在我的布局中,我正在检查视图是否设置了overlay view变量,然后在HTML中包含上一个操作的overlay,例如(controllerName和actionName ViewHelpers在引导上填充,因此包含
注册为controller等):

但它当前不包含来自registerAction的任何数据。我曾想过要有一个登记表,把所有与登记相关的事情都放在里面,让它在我可能转发到的任何地方都可以访问,但现在转发和传递变量变得相当复杂

我正在考虑创建一个ViewHelper,如
echo$this->overlay()
,它将包含来自上一个视图的ViewVariables,并将另一个视图作为一个部分包含在内,但还考虑通过转发调度程序将视图从registerAction传递到indexAction并嵌套它

现在,我在页面底部使用JS触发statechange,它获取当前URL并通过AJAX获取它,但让用户等待完整页面呈现,然后加载符号,这让人困惑,因为它可能已经存在了


这似乎是一个相当复杂的问题,因为我不太熟悉什么是可用的。我在eventManager中看到了很多模块,所以我想知道其他人会如何处理这个问题?

成功地做到了这一点,而且比我预期的要容易

// RegisterController/indexAction
public function registerAction()
{
    $request = $this->getRequest();

    $view = new ViewModel();

    // If we're not requesting via AJAX, forward dispatch to index
    if (!$request->isXmlHttpRequest()) {
        $view->setTemplate('application/register/index');
        return $this->forward()->dispatch('index', array(
            'action' => 'index',
            'overlay' => $view
        ));
    }

    $view->setTerminal(true);
    return $view;
}

// IndexController/indexAction
public function indexAction()
{
    $request = $this->getRequest();
    $routeRequest = $this->getEvent()->getRouteMatch();

    $view = new ViewModel();

    $overlay = $routeRequest->getParam('overlay', null);
    if (null !== $overlay) {
        $view->addChild($overlay, 'overlay');
    }

    return $view;
}

我对此唯一的不满是,在转发调度子视图之前,我必须手动设置该子视图的模板,因为如果未指定任何路径,它将在dispatch中填充默认路径

请正确格式化您的代码(即,
公共函数…
子句和ehte last
}
应包含在代码块中),并对其进行简要介绍。
public function registerAction () {
    $request = $this->getRequest();

    // Possible $form = new RegisterForm(); with validation and error population etc

    // If we're not requesting via AJAX, forward dispatch to index
    if (!$request->isXmlHttpRequest()) {
        return $this->forward()->dispatch('index', array(
            'action' => 'index',
            'overlay' => 1
        ));
    }

    $view = new ViewModel();
    $view->setTerminal(true);
    return $view;

}
public function registerAction () {
    $request = $this->getRequest();

    // Possible $form = new RegisterForm(); with validation and error population etc

    // If we're not requesting via AJAX, forward dispatch to index
    if (!$request->isXmlHttpRequest()) {
        return $this->forward()->dispatch('index', array(
            'action' => 'index',
            'overlay' => 1
        ));
    }

    $view = new ViewModel();
    $view->setTerminal(true);
    return $view;

}