Zend_Controller_Plugin_Abstract 重定向如何与完整的 url 更改一起工作?它使 Zend_layout 禁用布局失败
我有一个管理 webapp。在执行任何操作之前必须登录。现在 /default/index/index 具有登录表单,它是 ExtJs 组件。基本上登录过程是 ajax 过程。我创建了一个插件来禁用渲染和布局并检查用户是否登录(还没有完整的 acl)。
这是代码:
public function preDispatch(Zend_Controller_Request_Abstract $request) {
parent::preDispatch($request);
if($request->isXmlHttpRequest()){
$ViewHelper = Zend_Controller_Action_HelperBroker::getStaticHelper("ViewRenderer");
$ViewHelper->setNoRender(true);
Zend_Layout::getMvcInstance()->disableLayout();
}
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
if(!Zend_Auth::getInstance()->hasIdentity()){
$url = "/".$module."/".$controller."/".$action;
$session = new Zend_Session_Namespace("myapp.auth");
$session->requestURL = $url;
$request->setModuleName("default");
$request->setControllerName("index");
$request->setActionName("index");
$request->setDispatched();
}
}
这似乎有效,但地址栏仍然有原始的请求网址。 例如,我在网址栏中输入 "myapp/admin/cpanel"
,它会在浏览器上打开登录页面,而地址栏仍然有 "myapp/admin/cpanel"< /code>. 目前登录失败,因为输出有一些 html 渲染,我相信是来自登录页面(直接点击时工作正常)。
有没有人以前经历过这个,或者只是我做错了什么。如果你能分享你的经验,我会很高兴。
感谢您阅读本文。
I have an admin webapp.one have to login before perfoming any action.Now the /default/index/index has the login form which is an ExtJs component.basically the login process is an ajax one.i've created a plugin to disable the rendering and layout and to check whether user is logged in or not(no full acl yet).
here is the code:
public function preDispatch(Zend_Controller_Request_Abstract $request) {
parent::preDispatch($request);
if($request->isXmlHttpRequest()){
$ViewHelper = Zend_Controller_Action_HelperBroker::getStaticHelper("ViewRenderer");
$ViewHelper->setNoRender(true);
Zend_Layout::getMvcInstance()->disableLayout();
}
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
if(!Zend_Auth::getInstance()->hasIdentity()){
$url = "/".$module."/".$controller."/".$action;
$session = new Zend_Session_Namespace("myapp.auth");
$session->requestURL = $url;
$request->setModuleName("default");
$request->setControllerName("index");
$request->setActionName("index");
$request->setDispatched();
}
}
this seems to work but then the address bar still have the original request url.
for example i've typed "myapp/admin/cpanel"
in the url bar and it opens the login page on the browser while the address bar still has "myapp/admin/cpanel"
.at the moment the login fails because the output has some html rendering i believe is from the login page(which has been working fine when hit directly).
Has anyone has experienced this before or it's just me doing something wrong.I'will be glad if you can share your experience with this.
thanks for reading this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不喜欢这种行为,您可能需要考虑将用户重定向到登录表单,而不是在每个控制器之前处理登录。如果您的登录页面目前确实可以访问,那么这应该像写作一样简单:
虽然我无法测试它,但想法应该很清楚。
In case you dislike that behaviour, you might want to consider redirecting the user to the login-form, instead of handling the login before each and every controller. If your login page is actually accessible at the moment, this should be as trivial as writing:
I'm not able to test it though, but the thought should be clear.