我在我的网站上有覆盖和一个隐藏的面板,它使用AJAX从另一个控制器/动作中拉入内容。您只需单击一个链接,然后使用setTerminal(true);将URL和AJAX拉入内容,这样就不会出现任何环绕的布局。这些覆盖/隐藏面板是登录/注册的,当你请求没有ajax (刷新)的页面时,它们也希望它们已经在HTML中,这样它们就可以被深度链接到。
目前,我在寄存器控制器/操作中有类似这样的东西:
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:
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视图变量,然后在HTML语言中包含前一个操作的覆盖,例如(controllerName和actionName填充ViewHelpers,onBootstrap,因此包含register作为控制器,等等):
// Layout.phtml
if ($viewVariables->overlay) {
echo $this->partial('application/' . $this->controllerName() . '/' . $this->actionName() . '.phtml');
}但这目前并不包含来自registerAction的任何数据。我正在考虑有一个注册表,并在其中完成所有与注册相关的工作,并让它可以访问-我可以将调度转发到任何地方,但现在它变得相当复杂,转发和传递变量。
我正在考虑创建一个像echo $this->overlay()这样的ViewHelper,它将包含前一个视图中的ViewVariables,并将另一个视图作为部分视图包含在内,然后还考虑通过转发调度程序将视图从registerAction传递到indexAction,并对其进行嵌套。
现在,我用页面底部的JS触发了状态变化,它接受当前的URL并通过AJAX抓取它,但让用户等待整个页面呈现,然后在那之后加载符号是令人困惑的,因为它可能已经在那里了。
这似乎是一个相当复杂的问题,因为我不太熟悉可用的内容。我在eventManager中看到了很多模块,所以我想知道其他人会如何处理这个问题?
发布于 2013-05-23 17:51:11
成功地做到了这一点,这比我预期的要容易。
// 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;
}我对此唯一的抱怨是,在转发分派它之前,我必须手动设置子视图的模板,因为如果没有指定默认路径,它将填充onDispatch。
发布于 2014-07-29 19:10:47
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;
}https://stackoverflow.com/questions/16701910
复制相似问题