Skip to content
This repository was archived by the owner on Nov 28, 2018. It is now read-only.

support for prefixed wizardAction #7

Open
CaptainQuirk opened this issue Sep 9, 2011 · 0 comments
Open

support for prefixed wizardAction #7

CaptainQuirk opened this issue Sep 9, 2011 · 0 comments

Comments

@CaptainQuirk
Copy link

Hi,

My Wizard works just fine but I cannot make it work in the end. The _afterComplete ( ) method isn't called. My wizardAction is a prefixed action ( prefix_add ). I tried to set it in the cake array format but it seems to me that your plugin doesn't support it. The problem comes from here, I think :

line 234 to 248

          if ($proceed) {
        $this->save();
            if (next($this->steps)) {
           if ($this->autoAdvance) {
         $this->redirect();
           }

        $this->redirect(current($this->steps));
    } else {
        $this->Session->write('Wizard.complete', $this->read());        
            $this->reset();
        $this->controller->redirect($this->wizardAction);
    }
}

When there's a next step, you call Wizard::redirect that builds the url without paying attention to any prefix ( line 361 ). Cake seems to understand alone that it's a prefix, maybe because there's a parameter added at the end and renders the different steps correctly.

But when there is no next step however, you're using directly the Controller::redirect method. A prefix having already been set, the wizard tries in my case to redirect to the name of the method as it is set litterally in my beforeFilter callback but adds the prefix a second time, redirecting to a non existing prefix_prefix_add action.

I tried setting the url in the cake array format, but I fails right from the beginning because since the Wizard::redirect ( ) method calls the Controller::redirect with wizardAction as 'action' parameter, the Router crashes.

Here's what I'm proposing in Wizard::redirect ( ) :

function redirect($step = null, $status = null, $exit = true) {
    if ($step == null) {
        $step = $this->_getExpectedStep();
    }
            $controller = Inflector::underscore($this->controller->name);
            if (is_array($this->wizardAction)) {
              $url = $this->wizardAction;
              $url['controller'] = $controller;
            } else {
                $url = array('controller' => $controller , 'action' => $this->wizardAction);  
            }
    $url[] = $step;
    $this->controller->redirect($url, $status, $exit);
}

Changing the name of the wizardAction parameter to something like wizardUrl may also be interesting if you decide that supporting prefixes is necessary

Thanks for all the work, it saved me hours of work !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant