Issues

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

Issue Type: Bug Created: 2007-07-17T14:13:46.000+0000 Last Updated: 2008-09-02T10:39:47.000+0000 Status: Resolved Fix version(s): - 1.6.0 (02/Sep/08)

Reporter: Nick Howell (howellnick) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Controller

Related issues: Attachments:

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(); ...

<pre class="highlight">
if (null === $controller) {
    $controller = $request->getControllerName();
    if (empty($controller)) {
        $controller = $dispatcher->getDefaultControllerName();
    }
}

should be:

<pre class="highlight">
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:

<pre class="highlight">
if (null === $module) {
    $module = $request->getModuleName();
    if ($module == $dispatcher->getDefaultModule()) {
        $module = '';
    }
}

Should be:

<pre class="highlight">
if (null === $module) {
    $module = $request->getModuleName();
}
        
if ($module == $dispatcher->getDefaultModule()) {
    $module = '';
}

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

Comments

Posted by Darby Felton (darby) on 2007-07-19T16:01:53.000+0000

Assigning to [~matthew] to initiate issue review.

Posted by Matthew Weier O'Phinney (matthew) on 2007-09-14T12:13:57.000+0000

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

Posted by Jaka Jancar (jaka) on 2008-07-28T13:22:05.000+0000

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:

<pre class="highlight"> 
$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:

<pre class="highlight"> 
        if (null === $module) {
            $module = $request->getModuleName();
            if ($module == $dispatcher->getDefaultModule()) {
                $module = '';
            }
        }

to:

<pre class="highlight"> 
        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

Posted by Matthew Weier O'Phinney (matthew) on 2008-08-04T19:52:44.000+0000

Fixed in trunk and merged to 1.6 release branch.

Posted by Wil Sinclair (wil) on 2008-09-02T10:39:47.000+0000

Updating for the 1.6.0 release.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts