Zend Framework

Incorrect redirecting with $redirector->goto(null,null,'modulename');

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0.0, 1.0.1
  • Fix Version/s: 1.6.0
  • Component/s: Zend_Controller
  • Labels:
    None
  • Fix Version Priority:
    Must Have

Description

I have a $this->_redirector->goto(null,null,'admin'); inside my Admin_ClassController->viewAction() ...
What is expected to happen here is for the page to redirect to http://example.com/admin but it goes to http://example.com/admin/class instead. Granted, you can do a $this->_redirector->goto(null,'index','admin'); but then you get http://example.com/admin/index (I'd prefer to not have the extra /index on the end).

Looks like a problem in Zend_Controller_Action_Helper_Redirector->setGoto(); ...

if (null === $controller) {
    $controller = $request->getControllerName();
    if (empty($controller)) {
        $controller = $dispatcher->getDefaultControllerName();
    }
}

should be:

if (null === $controller) {
    if (null !== $action) {
        $controller = $request->getControllerName();
        if (empty($controller)) {
            $controller = $dispatcher->getDefaultControllerName();
        }
    }
}

The addition checks to see if the $action was set, THEN we can get the controller name if $controller was not set - otherwise leave $controller as null.
I tested this change in my application and the problem was solved.

This also keeps the functionality consistent as you can now do $this->_redirector->goto(null); and be redirected to the current module index rather than the controller you are currently in.

UPDATE:
I have found another problem here...
When doing a $this->_redirector->goto(null,null,'default'); you end up with the URL http://example.com/default instead of the plain old http://example.com/. This is also the case when doing something like $this->_redirector->goto('login','account','default'); you will end up getting the URL http://example.com/default/account/login instead of http://example.com/account/login.

Here is the change to fix this issue (separate from the issue above). This code:

if (null === $module) {
    $module = $request->getModuleName();
    if ($module == $dispatcher->getDefaultModule()) {
        $module = '';
    }
}

Should be:

if (null === $module) {
    $module = $request->getModuleName();
}
        
if ($module == $dispatcher->getDefaultModule()) {
    $module = '';
}

This fixes the issues I am having with it. Comments anyone?

Activity

Hide
Darby Felton added a comment -

Assigning to Matthew Weier O'Phinney to initiate issue review.

Show
Darby Felton added a comment - Assigning to Matthew Weier O'Phinney to initiate issue review.
Hide
Matthew Weier O'Phinney added a comment -

The redirector helper does not support null values for the $action parameter; you need to provide the action.

Show
Matthew Weier O'Phinney added a comment - The redirector helper does not support null values for the $action parameter; you need to provide the action.
Hide
Jaka Jancar added a comment -

The problem is exists even if you don't use null.

Say, for example, that you want to redirect to /default/index/index. If you want to write the redirection so it works from other modules also, you will write:

$this->_helper->redirector('index', 'index', 'default');

(as opposed to leaving out the third argument)

This will cause a redirection to "/default" instead of to "/" (redundant action and controller names get hidden, but the redundant module remains).

Please change:

Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
if (null === $module) {
            $module = $request->getModuleName();
            if ($module == $dispatcher->getDefaultModule()) {
                $module = '';
            }
        }

to:

if (null === $module) {
            $module = $request->getModuleName();
        }
        if ($module == $dispatcher->getDefaultModule()) {
            $module = '';
        }

since assigning the current module if it's null, and omitting the redundant module name (whether determined automatically or specified explicitly) are two separate actions.

Jaka

Show
Jaka Jancar added a comment - The problem is exists even if you don't use null. Say, for example, that you want to redirect to /default/index/index. If you want to write the redirection so it works from other modules also, you will write:
$this->_helper->redirector('index', 'index', 'default');
(as opposed to leaving out the third argument) This will cause a redirection to "/default" instead of to "/" (redundant action and controller names get hidden, but the redundant module remains). Please change:
Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
if (null === $module) {
            $module = $request->getModuleName();
            if ($module == $dispatcher->getDefaultModule()) {
                $module = '';
            }
        }
to:
if (null === $module) {
            $module = $request->getModuleName();
        }
        if ($module == $dispatcher->getDefaultModule()) {
            $module = '';
        }
since assigning the current module if it's null, and omitting the redundant module name (whether determined automatically or specified explicitly) are two separate actions. Jaka
Hide
Matthew Weier O'Phinney added a comment -

Fixed in trunk and merged to 1.6 release branch.

Show
Matthew Weier O'Phinney added a comment - Fixed in trunk and merged to 1.6 release branch.
Hide
Wil Sinclair added a comment -

Updating for the 1.6.0 release.

Show
Wil Sinclair added a comment - Updating for the 1.6.0 release.

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: