Rya*_*yan 5 php zend-framework
我正在尝试使用Zend创建一个登录系统,当用户尝试访问受限制的页面时,如果他们没有登录,他们将被带到登录页面.我遇到的问题是获取他们尝试的URL手前访问.是否有Zend函数将返回基本Url之后的所有内容?例如,我需要将"moduleName/controllerName/ActionName/param1/value1/param2/value2"等作为查询字符串参数发送到登录页面(例如:login /?redirect = controllerName/actionName/param1/value1 /参数2 /值)
我可以得到控制器和动作名称,我得到了参数,但它已经包括模块,控制器和动作.我想得到我需要的东西.我做了很多这样的事情:
$controllerName = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
$actionName = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
$paramArray = Zend_Controller_Front::getInstance()->getRequest()->getParams();
$params = '';
foreach($paramArray as $key => $value)
$params .= $key . "/" . $value;
$this->_redirect('/admin/login/?redirect=' . $controllerName . "/" . $actionName . "/" . $params);
Run Code Online (Sandbox Code Playgroud)
但即便如此,我最终还是使用了模块/ admin/controller/index /等参数,这是我不想要的.那么,我怎样才能将所有内容都像URL中的字符串一样,或者至少只是字符串中的params,而没有控制器和action作为param值?
**编辑:这是我目前的解决方案,但必须有一个更优雅的方式来做到这一点**
$moduleName = $this->getRequest()->getModuleName();
$controllerName = $this->getRequest()->getControllerName();
$actionName = $this->getRequest()->getActionName();
$paramArray = $this->getRequest()->getParams();
$params = '';
foreach($paramArray as $key => $value)
if($key <> "module" && $key <> "controller" && $key <> "action")
$params .= $key . "/" . $value . "/";
$this->_redirect('/admin/login/?redirect=' . $moduleName . "/" . $controllerName . "/" . $actionName . "/" . $params);
Run Code Online (Sandbox Code Playgroud)
我认为你可以像这样传递最后一个请求 URI:
$this->_redirect('/admin/login/?redirect='.urlencode($this->getRequest()->REQUEST_URI));
Run Code Online (Sandbox Code Playgroud)