Search code examples
yiiwizardyii-extensions

Yii - Wizard Behavior extension - Skipping Steps


I hope someone on stackoverflow has some experience with the Wizard Behavior extension: http://www.yiiframework.com/extension/wizard-behavior/

The problem is that when I click submit on the first page (user), it goes all the way to the billing page and skips the company page...help?

I have 3 steps to collect information: a user, company and billing page. Here is my behaviors function in my controller:

public function behaviors() {
    return array(
     'wizard'=>array(
      'class'=>'ext.WizardBehavior.WizardBehavior',
      'steps'=>array(
       'user','company','billing'
      )
     )
    )
}

This is my process step function:

public function wizardProcessStep($event) {
    $name = '_wizard'.ucfirst($event->step);
    if (method_exists($this, $name)) {
        call_user_func(array($this,$name), $event);
    } else {
        throw new CException(Yii::t('yii','{class} does not have a method named "{name}"', array('{class}'=>get_class($this), '{name}'=>$name)));
    }
}

Here is my company step as an example:

protected function _wizardCompany($event) {
    echo 'called company';
    exit();
    $company=new Company;
    if(isset($_POST['Company'])) {
        $company->attributes=$_POST['Company'];
        if($company->validate()) {
            $event->sender->save($company->attributes);
            $event->handled = true;
        }
    }
    $this->render('new_company',array(
        'company'=>$company,
        'event'=>$event,
    ));
}

Solution

  • this doesn't seem to be a bug, but by design. By default, WizardBehavior skips to the first unhandled step.

    You were probably testing your wizard and entered something into "User" and "Company". When you are now at "Billing", and go back to "User" (via url or link). enter something and submit again, it skips to billing because this is the first unhandled step. Notice that you can go to "Company" and all previously handled steps via the URL and links.

    This behavior can be set to false by

    public function behaviors() {
        return array(
         'wizard'=>array(
          'autoAdvance' => false,
         )
        )
    }
    

    Or you implement the onFinish event, so that the wizard is reset easily while testing.