Zend, How to access the current route from the Action Helper

In the Zend Framework, I have an action helper that loads a login form on most pages. This happens in the preDispatch () method of the Helper, and I want setAction () in the form so that it returns to the current URL.

What is the best way to access the current URL / route from the Assistant? Access the request (through the action controller), then pull getActionName () and getControllerName () and connect them to baseURL ()?

Is there an easier way? (A URI string is required to set an action as a parameter).

Thank!

+3
source share
3 answers

, URL/ Action Helper. , URL. .

+2

, @Elie. , ZF, :

    $request = Zend_Controller_Front::getInstance()->getRequest();
    echo $request->getHeader('referer'); // referer address
    echo $request->getRequestUri();      // current address
+5

If I understand correctly when a user logs in, you want to send them back to the page where they came from. The code I use for this:

// the user has come from a particular page - send them back
if($_SERVER['HTTP_REFERER']) {
    $this->_redirect($_SERVER['HTTP_REFERER']);
} else {
// the user has come from the home page, or this page
    $this->_redirect('/');
}

which is in the input action (i.e. LoginController->loginAction()).

0
source

All Articles