Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend - Get everything after base Url (Controller, Action, and any params)

I am trying to create a login system with Zend that when a user tries to access a restricted page they will be taken to a login page if they aren't signed in. The issue I'm having is getting the URL they were trying to access before hand. Is there a Zend Function that will return everything after the base Url? For example, I need "moduleName/controllerName/ActionName/param1/value1/param2/value2" etc etc. to be sent as a querystring param to the login page (ex: login/?redirect=controllerName/actionName/param1/value1/param2/value)

I can get the controller and action name, and I get get the params, but it already includes the module, controller, and action as well. I'd like to just get what I need. I worked out the long way of doing it like this:

$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);

but even then I end up with params like module/admin/controller/index/ etc which I don't want. So, how can I just get everything as a string like it is in the URL or at least just the params in a string without the controller and action as param values?

**EDIT: Here is my current solution, but there has got to be a more elegant way of doing this **

            $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);
like image 912
Ryan Avatar asked Jan 04 '10 18:01

Ryan


1 Answers

I think you can pass along the last request URI like this:

$this->_redirect('/admin/login/?redirect='.urlencode($this->getRequest()->REQUEST_URI));
like image 137
Derek Illchuk Avatar answered Nov 14 '22 21:11

Derek Illchuk